algorithm - Maximum xor of a range of numbers -
i grappling problem codeforces 276d. used brute force approach failed large inputs(it started when inputs 10000000000 20000000000). in tutorials fcdkbear(turtor contest) talks dp solution state d[p][fl1][fr1][fl2][fr2]
.
further in tutorial
need know, bits can place binary representation of number а in p-th position. can place 0 if following condition true: p-th bit of l equal 0, or p-th bit of l equal 1 , variable fl1 shows current value of strictly greater l. similarly, can place 1 if following condition true: p-th bit of r equal 1, or p-th bit of r equal 0 , variable fr1 shows current value of strictly less r. similarly, can obtain, bits can place binary representation of number b in p-th position.
this going on head when ith bit of l 0 how come can place 0 in a's ith bit. if l , r both in same bucket(2^i'th boundary 16 , 24) place 0 @ 4th whereas can place 1 if = 20 because i-th bit of r 0 , > r
. wondering use of checking if > l or not.
in essence not logic of
- what states are
- how recur
i know might overkill explain in descriptive manner editorial short explain anything.
i have looked in here suggested solution different 1 given in editorial. know can solved binary search concerned dp solution only
if got problem right: start compare bits of l , r left (msb) right(lsb). long these bits equal there no freedom of choice, same bits must appear in , b. first bit differing must 1 in r , 0 in l. must appear in (0) , b(1). here can maximise xor result. use zeros b ones a. gives a+1==b , xor result a+b 2^n-1.
Comments
Post a Comment