Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

Блог пользователя rachitiitr

Автор rachitiitr, история, 9 лет назад, По-английски

http://rachitiitr.blogspot.in/2017/06/a-superb-problem-on-hashing-queries-on.html

This was my favorite problem from the recent long contest from CodeChef.
I solved the problem by building up a solution from scratch, and feel it's worth sharing.
Here is what other things you can learn from this post:
1. How to check whether two sets are identical using hashing.
2. An easy data structure to find the number of elements less than K in subarray A[L...R].
3. A variant of BIT i.e fenwick tree. We can use BITs for a lot of purposes :)

Have a good day!

  • Проголосовать: нравится
  • +86
  • Проголосовать: не нравится

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can we use binary search?

  1. Associate a random large value for each distinct element.
  2. Precompute prefix xor of these associated values going by order of the given array.
  3. compare xor of left and right halves of both the query segments. At most one of the two halves can differ.
»
9 лет назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

Hey why you are doing so much for computing mismatched value x,y ? compute prefix square sum and prefix sum ! if you subtract the prefix square sum of two ranges you will get =x^2 - y^2 if you subtract prefix sum you get = x-y now you you can easily find x and y !

AC Code

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What is the idea you used to find rank of the found values x and y in the corresponding subarray? I used sorting. It can lead to TLE but my code is giving WA even for small system tests. I have used prefix sum to find mismatch. It will be great if someone can help. I have wasted around 4 hours.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +28 Проголосовать: не нравится

I am the author of this problem and I am glad that people liked this problem.

I am also surprised by all the different kinds of solutions that came in. Including sqrt, persistence, xor, etc since I myself knew only 1 — 2 different type of solutions.

Kudos to Rachit for figuring out the unique xor way for obtaining x and y.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится