File tree 1 file changed +7
-11
lines changed
1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -87,23 +87,19 @@ def insert(self, num):
87
87
self .__maxs [curr ] = max (self .__maxs [curr ], num )
88
88
89
89
def query (self , num ):
90
- result = curr1 = curr2 = 0
90
+ result = curr = 0
91
91
for i in reversed (xrange (self .__bit_length )):
92
92
result <<= 1
93
93
x = num >> i
94
94
y = (result | 1 )^ x
95
- assert (x != y )
96
- a , b = self .__nodes [curr1 ][x & 1 ], self .__nodes [curr2 ][y & 1 ]
97
- if x < y :
98
- a , b = b , a
99
- if self .__nodes [curr2 ][y & 1 ] != - 1 and self .__mins [a ] <= 2 * self .__maxs [b ]:
95
+ assert (x != y )
96
+ if (self .__nodes [curr ][y & 1 ] != - 1 and
97
+ ((x > y and num <= 2 * self .__maxs [self .__nodes [curr ][y & 1 ]]) or
98
+ (x < y and self .__mins [self .__nodes [curr ][y & 1 ]] <= 2 * num ))):
100
99
result |= 1
101
- curr2 = self .__nodes [curr2 ][y & 1 ]
102
- elif self .__nodes [curr2 ][(y & 1 )^ 1 ] != - 1 :
103
- curr2 = self .__nodes [curr2 ][(y & 1 )^ 1 ]
100
+ curr = self .__nodes [curr ][y & 1 ]
104
101
else :
105
- break
106
- curr1 = self .__nodes [curr1 ][x & 1 ]
102
+ curr = self .__nodes [curr ][1 ^ (y & 1 )]
107
103
return result
108
104
109
105
trie = Trie (max (nums ).bit_length ())
You can’t perform that action at this time.
0 commit comments