QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#606300 | #8940. Piggy Sort | ucup-team3646# | RE | 0ms | 0kb | Python3 | 2.2kb | 2024-10-03 00:30:23 | 2024-10-03 00:30:23 |
answer
# from sys import stdin
# input = lambda: stdin.readline()
import random
debug = 0
N = 1
P = []
ask_cnt = 0
ask_len = 0
def ask(l, r):
global ask_cnt, ask_len
ask_len += r - l
ask_cnt += 1
# assert r - l >= 2
if debug:
res = []
for i in range(l, r):
res.append((P[i], i))
res.sort()
# print(res)
return res[-2][1]
else:
print("?", l + 1, r, flush=True)
pos = int(input()) - 1
return pos
import math
def ans(pos):
if debug:
assert P[pos] == N - 1
print(N, ask_cnt, ask_len)
assert ask_len <= 3 * N
assert ask_cnt <= math.ceil(1.5 * math.log2(N))
else:
print("!", pos + 1, flush=True)
if debug:
T = 10**6
else:
T = int(input())
for _ in range(T):
if debug:
N = random.randint(5, 20)
P = list(range(N))
random.shuffle(P)
else:
N = int(input())
ask_cnt = 0
ask_len = 0
def calc(L, R, pos2):
if R - L == 2:
if pos2 == -1:
pos2 = ask(L, R)
if pos2 == L:
ans(L + 1)
else:
ans(L)
return
if R - L == 3:
p = ask(L, L + 3)
if p == L + 1:
q = ask(L, L + 2)
if p == q:
ans(L)
else:
ans(R - 1)
elif p == L:
calc(L + 1, R, -1)
else:
calc(L, R - 1, -1)
return
if pos2 == -1:
pos2 = ask(L, R)
d = int((R - L) / 1.618034)
d = min(R - L - 2, max(d, 2))
print(R - L, d)
mid = L + d
if pos2 < mid:
pos = ask(L, mid)
if pos == pos2:
calc(L, mid, pos)
else:
calc(mid, R, -1)
else:
mid = R - d
pos = ask(mid, R)
if pos != pos2:
calc(L, mid, -1)
else:
calc(mid, R, pos)
calc(0, N, ask(0, N))
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
3 2 4 1 2 3 4 5 6 7 8 1 2 1 1 3 4 1 2 3 6 9 9 10 15 17 12 18 21