ANDSQR - Editorial

Thanks dear <33333333333

…agree :smiley:

It should be N log (max(A[i])) instead of N log N.

Aah, yup XD. My bad.

me too…

An alternative sorting order for Mo's algorithm - Codeforces - here is it, an improvement of Mo’s algorithm

*Hilbert order

1 Like

Here you should apply the concept. Fenwick tree was used only for a simple range update. The concept of AND was used in preprocessing part. That thing sadly doesnt hold for XOR, so the preprocessing part fails for XOR, but if you can come up with something for that, then fenwick tree can be used in next step.

We are interested in places where AND changes. We hence dont care about bits which are 0. And why n+1? Thats depends on implementation and definition you used. This guy used “Let it store beginning of next group w.r.t that bit.” so it makes sense.

You can look at the model solution shared for full code.

whenever 0 is encounter in any of j th bit then that’s the case when And changes as set bit might get off ; yep it might be case that it might be off before we didn’t need to worry about this case.

@vijju123 Can you tell me what is the meaning of that star ? in P*[j] ? Really hard for me to understand :frowning: Any ideas @l_returns.

1 Like

Akaik
P*[j] means pointer to first element of array.
See implementation below explanation.
You’ll understand.

Though m not sure at all. Vijju can confirm that.
PS: I haven’t read editorial thoroughly yet.

1 Like

Good catch. AFAIR, the editorial’s formatting messed up when moving from old to new discuss and was manually fixed. I am pretty sure that was P[i][j] there.

2 Likes

Thankyousomuch​:heart_eyes::heart_eyes::heart_eyes::blush::blush::blush::blush::blush:

1 Like