11#encoding:utf-8
2- #Created by Liang Sun on May, 6, 2013
32class SegmentTree (object ):
43 def __init__ (self , start , end ):
54 self .start = start
@@ -30,7 +29,7 @@ def _init(self, start, end):
3029 self .sum_value [(start , end )] = 0
3130 self .len_value [(start , end )] = 0
3231 if start < end :
33- mid = start + ( end - start ) / 2
32+ mid = start + int (( end - start ) / 2 )
3433 self ._init (start , mid )
3534 self ._init (mid + 1 , end )
3635
@@ -42,7 +41,7 @@ def _add(self, start, end, weight, in_start, in_end):
4241 self .len_value [key ] = 1 if self .sum_value [key ] > 0 else 0
4342 return
4443
45- mid = in_start + ( in_end - in_start ) / 2
44+ mid = in_start + int (( in_end - in_start ) / 2 )
4645 if mid >= end :
4746 self ._add (start , end , weight , in_start , mid )
4847 elif mid + 1 <= start :
@@ -58,7 +57,7 @@ def _query_max(self, start, end, in_start, in_end):
5857 if start == in_start and end == in_end :
5958 ans = self .max_value [(start , end )]
6059 else :
61- mid = in_start + ( in_end - in_start ) / 2
60+ mid = in_start + int (( in_end - in_start ) / 2 )
6261 if mid >= end :
6362 ans = self ._query_max (start , end , in_start , mid )
6463 elif mid + 1 <= start :
@@ -73,7 +72,7 @@ def _query_sum(self, start, end, in_start, in_end):
7372 if start == in_start and end == in_end :
7473 ans = self .sum_value [(start , end )]
7574 else :
76- mid = in_start + ( in_end - in_start ) / 2
75+ mid = in_start + int (( in_end - in_start ) / 2 )
7776 if mid >= end :
7877 ans = self ._query_sum (start , end , in_start , mid )
7978 elif mid + 1 <= start :
@@ -86,7 +85,7 @@ def _query_len(self, start, end, in_start, in_end):
8685 if start == in_start and end == in_end :
8786 ans = self .len_value [(start , end )]
8887 else :
89- mid = in_start + ( in_end - in_start ) / 2
88+ mid = in_start + int (( in_end - in_start ) / 2 )
9089 if mid >= end :
9190 ans = self ._query_len (start , end , in_start , mid )
9291 elif mid + 1 <= start :
0 commit comments