QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#542629 | #8939. Permutation | ucup-team1231# | RE | 412ms | 10684kb | Python3 | 2.4kb | 2024-09-01 03:19:58 | 2024-09-01 03:19:59 |
Judging History
answer
import sys
T = int(input())
def calc(u):
if u<=1: return 0
if u==2: return 1
if u==3: return 2
return 3+calc((u+3)//4)
def qry(a,b):
if a==b:
return -1
print('?',a,b)
sys.stdout.flush()
return int(input())
def sol():
n = int(input())
L, R = 1, n
while R-L+1 >= 4:
u = R-L+1
fid = [L+u*i//4 for i in [0,1,2,3,4]]
x = qry(L, R)
# [fid[t],fid[t+1])
inseg = lambda t,u: fid[t]<=u<fid[t+1]
if inseg(0,x) or inseg(1,x):
if qry(fid[0],fid[2]-1) == x:
if inseg(0,x):
if qry(fid[0],fid[1]-1) == x:
L, R = fid[0], fid[1]-1
else:
L, R = fid[1], fid[2]-1
else:
if qry(fid[1],fid[2]-1) == x:
L, R = fid[1], fid[2]-1
else:
L, R = fid[0], fid[1]-1
else:
if qry(fid[0],fid[3]-1) == x:
L, R = fid[2], fid[3]-1
else:
L, R = fid[3], fid[4]-1
else:
if qry(fid[2],fid[4]-1) == x:
if inseg(3,x):
if qry(fid[3],fid[4]-1) == x:
L, R = fid[3], fid[4]-1
else:
L, R = fid[2], fid[3]-1
else:
if qry(fid[2],fid[3]-1) == x:
L, R = fid[2], fid[3]-1
else:
L, R = fid[3], fid[4]-1
else:
if qry(fid[1],fid[4]-1) == x:
L, R = fid[1], fid[2]-1
else:
L, R = fid[0], fid[1]-1
ans = -1
if R-L+1 == 3:
x = qry(L,L+2)
if x == L:
L = x+1
elif x == R:
R = x-1
else:
assert x == L+1
u = qry(L,x)
if u == x:
ans = L
else:
ans = R
if ans == -1:
if R-L+1 == 2:
ans = qry(L,R)^L^R
else:
assert R-L+1 == 1
ans = L
print('!',ans)
sys.stdout.flush()
import math
for i in range(1,100):
c = calc(i)
u = math.ceil(math.log2(i)*1.5)
if c>u:
print(i,c,u)
for _ in range(T):
sol()
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 18ms
memory: 10556kb
input:
3 5 3 3 5 6 6 5 6 3 4 3 3
output:
? 1 5 ? 3 5 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 2 6 ? 2 3 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 304ms
memory: 10684kb
input:
10000 10 2 2 1 3 5 10 10 10 8 7 10 5 1 5 6 10 4 4 4 4 4 10 10 6 3 2 10 3 3 5 2 10 1 5 5 9 9 10 1 3 1 6 10 2 4 4 9 8 10 3 3 3 3 5 10 4 1 7 8 9 10 8 7 8 4 4 10 4 1 1 9 8 10 7 8 7 4 3 10 5 1 1 8 10 10 8 8 8 8 9 10 2 1 2 7 10 6 6 7 10 8 10 1 3 1 6 10 7 9 7 5 4 10 7 8 7 4 4 10 3 4 4 10 8 10 4 4 4 4 3 10 ...
output:
? 1 10 ? 1 5 ? 1 2 ? 3 5 ? 4 5 ! 4 ? 1 10 ? 6 10 ? 8 10 ? 6 7 ! 6 ? 1 10 ? 1 5 ? 1 7 ? 6 7 ! 7 ? 1 10 ? 1 5 ? 3 5 ? 3 5 ? 3 4 ! 3 ? 1 10 ? 6 10 ? 3 10 ? 1 2 ! 1 ? 1 10 ? 1 5 ? 3 5 ? 1 2 ! 1 ? 1 10 ? 1 5 ? 1 7 ? 8 10 ? 8 9 ! 8 ? 1 10 ? 1 5 ? 1 7 ? 6 7 ! 7 ? 1 10 ? 1 5 ? 1 7 ? 8 10 ? 8 9 ! 10 ? 1 10 ?...
result:
ok Correct (10000 test cases)
Test #3:
score: 0
Accepted
time: 326ms
memory: 10684kb
input:
10000 3 1 2 11 5 3 5 8 7 2 2 19 3 4 3 13 12 12 7 5 7 5 2 3 3 1 19 6 6 7 1 2 1 2 2 15 11 11 11 11 10 11 14 1 1 3 5 5 16 4 4 1 8 7 8 3 3 2 19 13 17 5 2 1 2 2 2 4 1 2 3 7 2 2 3 3 2 2 17 1 1 2 8 7 6 14 9 9 9 9 8 20 9 3 9 13 14 13 6 4 4 5 18 7 7 7 7 7 9 8 8 6 8 3 8 6 7 6 3 16 10 10 10 10 10 6 1 3 1 10 3 ...
output:
? 1 3 ? 2 3 ! 3 ? 1 11 ? 1 5 ? 1 8 ? 6 8 ? 6 7 ! 6 ? 1 2 ! 1 ? 1 19 ? 1 9 ? 1 14 ? 10 14 ? 12 14 ? 11 14 ! 10 ? 1 7 ? 4 7 ? 2 7 ? 2 3 ! 3 ? 1 3 ? 1 2 ! 2 ? 1 19 ? 1 9 ? 5 9 ? 1 4 ? 1 2 ? 1 3 ! 3 ? 1 2 ! 1 ? 1 15 ? 8 15 ? 8 11 ? 8 11 ? 10 11 ? 9 11 ! 9 ? 1 14 ? 1 7 ? 1 3 ? 4 7 ? 4 5 ! 4 ? 1 16 ? 1 8 ...
result:
ok Correct (10000 test cases)
Test #4:
score: 0
Accepted
time: 412ms
memory: 10680kb
input:
10000 47 23 23 19 11 9 11 5 3 14 8 8 8 8 9 25 6 12 6 13 13 15 7 4 4 4 4 9 2 2 2 2 27 27 27 27 27 24 27 23 21 7 7 6 5 5 5 5 43 41 37 21 7 8 8 1 22 6 4 14 20 20 21 34 29 25 29 17 17 17 17 16 42 20 20 20 20 20 19 17 16 47 21 21 21 21 21 22 19 19 41 25 25 30 33 34 33 36 38 19 17 17 16 12 13 12 21 14 14 ...
output:
? 1 47 ? 1 23 ? 12 23 ? 1 11 ? 6 11 ? 3 11 ? 3 5 ? 3 4 ! 4 ? 1 14 ? 8 14 ? 8 10 ? 8 10 ? 9 10 ! 10 ? 1 25 ? 1 12 ? 1 18 ? 13 18 ? 13 15 ? 14 15 ! 14 ? 1 7 ? 4 7 ? 4 5 ? 4 5 ! 5 ? 1 9 ? 1 4 ? 1 2 ? 1 2 ! 1 ? 1 27 ? 14 27 ? 21 27 ? 21 27 ? 24 27 ? 22 27 ? 22 23 ! 22 ? 1 21 ? 1 10 ? 6 10 ? 1 5 ? 3 5 ? ...
result:
ok Correct (10000 test cases)
Test #5:
score: -100
Dangerous Syscalls
input:
10000 100 47 5 47 61 53 68 71 71 71 71 9 2 2 1 4 53 46 35 14 6 6 6 6 4 33 3 16 16 31 31 31 31 32 82 60 42 60 29 29 28 23 23 24 88 39 8 39 59 59 59 59 59 60 71 24 29 29 59 59 59 59 58 60 61 92 52 52 56 88 88 88 88 89 88 24 11 11 9 5 5 6 66 51 51 66 45 43 45 39 38 40 92 43 43 38 20 20 20 20 20 19 48 1...
output:
? 1 100 ? 1 50 ? 1 75 ? 51 75 ? 51 62 ? 51 68 ? 69 75 ? 69 71 ? 70 71 ? 70 71 ! 70 ? 1 9 ? 1 4 ? 1 2 ? 3 4 ! 3 ? 1 53 ? 27 53 ? 14 53 ? 1 13 ? 1 6 ? 4 6 ? 4 6 ? 4 5 ! 5 ? 1 33 ? 1 16 ? 1 24 ? 25 33 ? 29 33 ? 31 33 ? 31 33 ? 32 33 ! 33 ? 1 82 ? 42 82 ? 21 82 ? 21 41 ? 21 30 ? 26 30 ? 21 25 ? 23 25 ? ...