Mitpro's blog

By Mitpro, 2 months ago, In English

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)

  • Vote: I like it
  • +26
  • Vote: I do not like it

»
2 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
Spoiler
»
2 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
Spoiler
»
2 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

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 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

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

    Rest of Conversation
  • »
    »
    2 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    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 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      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 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
Spoiler
»
2 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it
Spoiler
»
2 months ago, hide # |
Rev. 5  
Vote: I like it 0 Vote: I do not like it
Spoiler
»
2 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it
Solution
»
2 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it
Spoiler
»
2 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

deleted

»
2 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it
Solution
  • »
    »
    2 months ago, hide # ^ |
     
    Vote: I like it +4 Vote: I do not like it

    YES! That was my original intended solution, but no one used it to solve my problem :(

    • »
      »
      »
      2 months ago, hide # ^ |
      Rev. 3  
      Vote: I like it 0 Vote: I do not like it
      But
      • »
        »
        »
        »
        2 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it
        Spoiler
    • »
      »
      »
      2 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      :)

»
2 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
sol
»
2 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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