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

Автор Mitpro, 2 месяца назад, По-английски

This is a cool problem I thought of, I challenge you to solve it (please put the solution in spoiler in the comments):

This is an interactive problem

There is a hidden array $$$a$$$ of size $$$n$$$.

You can ask at most $$$2n$$$ queries of type:

  • $$$?$$$ $$$i$$$ $$$j$$$ ($$$1 \le i \le j \le n$$$) — the jury will answer $$$a_i$$$ $$$\oplus$$$ $$$a_j$$$. Where $$$\oplus$$$ denotes the bitwise XOR operation.

After done asking the jury, you should output "$$$!$$$" to mark as finished. Then you need to handle a total of $$$q$$$ queries of type:

  • $$$l$$$ $$$r$$$ — compute $$$a_l$$$ $$$\oplus$$$ $$$a_r$$$

Output the answer for each query.

You can't be slick and ask all the queries at first because you don't know the queries yet, you have to ask, then the jury will give you the queries

Input:

  • The first line contains $$$2$$$ integers $$$n, q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the size of array $$$a$$$ and the number of queries

What is your stratergy to solving this?

Can you solve with strictly less than n queries to the jury and not using a temporary element?

gkos, Hyder1102, nik_exists, zeyd1234, SrabonGitikar, srvntofthejudge (sorry for pinging, just wanted to know how you would solve this)

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

»
2 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
Spoiler
»
2 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
Spoiler
»
2 месяца назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

A rather interesting problem would be to interact with same ai ^ aj queries, but the queries asked by the jury should be range queries (l,r)

Solution
  • »
    »
    2 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Before I finished reading the problem, I thought it was asking for this.

    Rest of Conversation
  • »
    »
    2 месяца назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    What does "results in even number of distinct elments" mean? XOR is just one result. A proof for your -1 is that if replace each $$$a_i$$$ with $$$a_i \oplus x$$$ for some $$$x$$$, then the answer of all queries asked by you remains the same while the result of an odd sized query asked by the judge is different.

    • »
      »
      »
      2 месяца назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      okay so what i meant is,

      lets say A is the xor of x different indices, (need not be contiguos) and B is the xor of y different indices,

      then A^B must have the xor of x + y indices, minus common elements in both A and B which get reduced from both x and y.

      so — 2*delta

      Hence if x and y are even, then so should x + y — 2 * delta be

»
2 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
Spoiler
»
2 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
Spoiler
»
2 месяца назад, скрыть # |
Rev. 5  
Проголосовать: нравится 0 Проголосовать: не нравится
Spoiler
»
2 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
Solution
»
2 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
Spoiler
»
2 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

deleted

»
2 месяца назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится
Solution
»
2 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
sol
»
2 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Everyone is solving this problem under n queries. what was the intended solution for 2n queries?