QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#542792#8939. Permutationucup-team1231#RE 0ms0kbPython33.9kb2024-09-01 05:44:322024-09-01 05:44:34

Judging History

This is the latest submission verdict.

  • [2024-09-01 05:44:34]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-09-01 05:44:32]
  • Submitted

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)
import math
cnt = 0
arr = []
tl = 0
def qry(a,b):
    if a==b:
        return -1
    # u = list(range(a,b+1))
    # global cnt
    # global tl
    # tl += b-a+1
    # cnt += 1
    # u.sort(key=lambda s:-arr[s])
    # return u[1]
    print('?',a,b)
    sys.stdout.flush()
    return int(input())
def sol():
    import random
    # n = random.randint(1,100)
    n = int(input())
    global cnt, arr, tl
    arr = list(range(1,n+1))
    random.shuffle(arr)
    arr = [0] + arr
    cnt = 0
    tl = 0
    up = math.ceil(math.log2(n)*1.5)
    L, R = 1, n
    while R-L+1 >= 4:
        u = R-L+1
        ls = [u*i//4-u*(i-1)//4 for i in [1,2,3,4]]
        ls.sort()
        x = qry(L, R)
        if R-L+1 in [4,5]:
            if x == L:
                L += 1
                continue
            elif x == R:
                R -= 1
                continue
        # [fid[t],fid[t+1])
        c0 = 10**9
        fid0 = None
        def upd(fid):
            nonlocal c0, fid0
            inseg = lambda t,u: fid[t]<=u<fid[t+1]
            if inseg(0,x) or inseg(1,x):
                co = fid[2]+fid[3]-fid[0]*2
            else:
                co = fid[4]*2-fid[1]-fid[2]
            if co>=c0: return
            c0 = co
            fid0 = fid
        upd([L,L+ls[0],L+ls[0]+ls[1],L+ls[0]+ls[1]+ls[2],L+sum(ls)])
        upd([L,L+ls[0],L+ls[0]+ls[1],L+ls[0]+ls[1]+ls[-1],L+sum(ls)])
        ls = ls[::-1]
        upd([L,L+ls[0],L+ls[0]+ls[1],L+ls[0]+ls[1]+ls[2],L+sum(ls)])
        upd([L,L+ls[1],L+ls[0]+ls[1],L+ls[0]+ls[1]+ls[2],L+sum(ls)])
        fid = fid0
        inseg = lambda t,u: fid[t]<=u<fid[t+1]
        print(R-L+1,[L,x,R])
        if inseg(0,x) or inseg(1,x):
            # x = 0
            # [0,2]
            print('A',fid[2]-fid[0])
            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:
                print('B',fid[3]-fid[0])
                if qry(x,fid[3]-1) == x:
                    L, R = fid[2], fid[3]-1
                else:
                    L, R = fid[3], fid[4]-1
        else:
            print('a',fid[4]-fid[2])
            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:
                print('b',fid[4]-fid[1])
                if qry(fid[1],x) == x:
                    L, R = fid[1], fid[2]-1
                else:
                    L, R = fid[0], fid[1]-1

    ans = -1
    # print(R-L+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)#,'@@',tl,'@@',n,'CC',cnt,'w',up)
#    print(arr[ans])
    # assert cnt <= up
    # assert ans!=-1 and arr[ans] == n
    # assert tl <= n*3##+2 #+2
    sys.stdout.flush()
for _ in range(T):
    sol()

详细

Test #1:

score: 0
Dangerous Syscalls

input:

3
5
3

output:

? 1 5
5 [1, 3, 5]
a 3
? 3 5

result: