An Interesting Mathematical Interactive Problem

Revision en4, by salehin_076923, 2025-05-21 17:07:35

Problem Name: Chocolate Bunny

Problem Rating: 1600

Problem Link: https://mirror.codeforces.com/problemset/problem/1407/C

[If I make any mistake, please pardon me & correct me!]

In this problem, we can ask 2 indices(x,y) in 1 query & get P[x] mod P[y]. Our limitation is we can ask no more than 2*n queries. Here is the main trick! If we were allowed to ask n^2 queries, we could easily do it asking ? x y for each x (1->n) and each y (1->n except x)

e.g. if n=5, to get a[3] we can ask

?1 3

?2 3

?4 3

?5 3

All these results must be all numbers 1<=r<a[3](r can also be 0 for some numbers), so a[3]=max(all remainders)+1

But as we can ask no more than 2*n queries, we have to focus on the mathematical property of MOD.

Let's think about a mod b & b mod a: If a>b, then a mod b<b; and b mod a = b<b

So if we ask ? x y and ? y x, we get a[x]%a[y] and a[y]%a[x], Between these, the max one is the real one that exists in the Permutation & the min one is the changed remainder of the max one. So if a[x]%a[y]>a[y]%a[x], then P[x]=a[x], then x++ and compare x with the previous y.And if a[y]%a[x]>a[x]%a[y], P[y]=a[y], y=x, x++.[Here we are iterating over x] Thus we can get (n-1) numbers except the max one which we all know to be n.

Here Queries used 2*(n-1)=2*n-2

Complexity: O(2*n)

My Submission: https://mirror.codeforces.com/contest/1407/submission/320641205

Tags mathematics, interactive

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en16 English salehin_076923 2025-05-22 09:41:32 0 (published)
en15 English salehin_076923 2025-05-22 09:41:05 7 Tiny change: 'ot (n-1)=2*n-2$\n\nCo' -> 'ot (n-1)=2\cdot n-2$\n\nCo'
en14 English salehin_076923 2025-05-22 09:40:06 20
en13 English salehin_076923 2025-05-22 09:38:12 11
en12 English salehin_076923 2025-05-22 09:36:23 1288
en11 English salehin_076923 2025-05-22 09:27:21 15
en10 English salehin_076923 2025-05-21 22:25:23 12
en9 English salehin_076923 2025-05-21 22:21:16 6 Tiny change: 'n\n`?1 3\n\n?2 3\n\n?4 3\n\n?5 3`\n\' -> 'n\n`?1 3\n?2 3\n?4 3\n?5 3`\n\'
en8 English salehin_076923 2025-05-21 22:20:49 12
en7 English salehin_076923 2025-05-21 22:19:56 14 (saved to drafts)
en6 English salehin_076923 2025-05-21 17:10:25 2 Tiny change: ' over x]\n Thus we' -> ' over x]\n\n Thus we'
en5 English salehin_076923 2025-05-21 17:09:11 9 Tiny change: ' mod a = b<b\n\nSo if' -> ' mod a = b> a mod b\n\nSo if'
en4 English salehin_076923 2025-05-21 17:07:35 22
en3 English salehin_076923 2025-05-21 17:05:52 798
en2 English salehin_076923 2025-05-21 17:03:30 22
en1 English salehin_076923 2025-05-21 17:00:33 2257 Initial revision (published)