Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 52

array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1)

st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1)

st.resize(4 * n)
build(8, 0, 0) build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1)

st.resize(4 * n)
build(8, 0, 0) build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 5 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1)

st.resize(4 * n)
build(8, 0, 0) build(1, 0, n – 1)
5
def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 5 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1)

st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(1, 0, n – 1)
5
def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 5 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1)

st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(1, 0, n – 1)
5
def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 0 0 0 0 5 -10 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1)

st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(1, 0, n – 1)
5 -10
def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 0 0 0 5 -10 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1)
-5
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(1, 0, n – 1)
5 -10
def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 0 0 0 5 -10 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1) build(5, 2, 3)
-5
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(1, 0, n – 1)
5
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 0 0 0 5 -10 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1) build(5, 2, 3)
-5
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(1, 0, n – 1)
5
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 0 0 0 5 -10 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1) build(5, 2, 3)
-5
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(1, 0, n – 1)
5
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 0 0 0 5 -10 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1) build(5, 2, 3)
-5
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(1, 0, n – 1)
5
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 0 0 0 5 -10 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1) build(5, 2, 3)
-5
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(1, 0, n – 1)
5
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 0 0 0 5 -10 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1) build(5, 2, 3)
-5
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(1, 0, n – 1)
5
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 0 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1) build(5, 2, 3)
-5
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(1, 0, n – 1)
5 2
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 0 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1) build(5, 2, 3)
-5
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(1, 0, n – 1)
5 2
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 0 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1) build(5, 2, 3)
-5
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(1, 0, n – 1)
5 2
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 0 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1) build(5, 2, 3)
-5
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(1, 0, n – 1)
5 2 0
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 0 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

build(4, 0, 1) build(5, 2, 3)
-5 2
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(1, 0, n – 1)
5 2 0
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3)

-3
build(4, 0, 1) build(5, 2, 3)
-5 2
st.resize(4 * n)
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(1, 0, n – 1)
5 2 0
-10 def build(i, cl, cr):
if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1, cr)
st[i] = st[2 * i] + st[2 * i +
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3)

5 -10 2 0
st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3)

5 -10 2 0
st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3)

5 -10 2 0
st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3)

5 -10 2 0
st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5)
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3)

5 -10 2 0
st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5)
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3)

5 -10 2 0
st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5)
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3)

5 -10 2 0
st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5)
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3)

5 -10 2 0
st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5)
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4)

5 -10 2 0
st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5)
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4)

5 -10 2 0
st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 4 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5)
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4)

5 2 0 4
-10 st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 4 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5)
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4) build(13, 5, 5)

5 2 0 4
-10 st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 4 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5)
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4) build(13, 5, 5)

5 2 0 4
-10 st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 0 0 5 -10 2 0 4 3

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5)
build(4, 0, 1) build(5, 2, 3)
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4) build(13, 5, 5)

5 2 0 4 3
-10 st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 7 0 5 -10 2 0 4 3

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5)
build(4, 0, 1) build(5, 2, 3)
7
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4) build(13, 5, 5)

5 2 0 4 3
-10 st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 7 0 5 -10 2 0 4 3

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5) build(7, 6, 6)
build(4, 0, 1) build(5, 2, 3)
7
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4) build(13, 5, 5)

5 2 0 4 3
-10 st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 7 0 5 -10 2 0 4 3

0 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5) build(7, 6, 6)
build(4, 0, 1) build(5, 2, 3)
7
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4) build(13, 5, 5)

5 2 0 4 3
-10 st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 0 -5 2 7 0 5 -10 2 0 4 3

1 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3
build(6, 4, 5) build(7, 6, 6)
build(4, 0, 1) build(5, 2, 3)
7 1
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4) build(13, 5, 5)

5 2 0 4 3
-10 st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 0 -3 8 -5 2 7 0 5 -10 2 0 4 3

1 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

build(2, 0, 3) build(3, 4, 6)

-3 8
build(6, 4, 5) build(7, 6, 6)
build(4, 0, 1) build(5, 2, 3)
7 1
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4) build(13, 5, 5)

5 2 0 4 3
-10 st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)
array 5 -10 2 0 4 3 1

st 0 5 -3 8 -5 2 7 0 5 -10 2 0 4 3

1 0 0 0 0 0 0 0 0 0 0 0 0 0
build(1, 0, 6)

5
build(2, 0, 3) build(3, 4, 6)

-3 8
build(6, 4, 5) build(7, 6, 6)
build(4, 0, 1) build(5, 2, 3)
7 1
-5 2
build(8, 0, 0) build(9, 1, 1) build(10, 2, 2) build(11, 3, 3) build(12, 4, 4) build(13, 5, 5)

5 2 0 4 3
-10 st.resize(4 * n)
build(1, 0, n – 1)

def build(i, cl, cr):


if cl == cr:
st[i] = array[cl]
else:
m = cl + (cr – cl) / 2
build(2 * i, cl, m)
build(2 * i + 1, m + 1,
cr)

You might also like