Iamtui1010

Interview.py

Apr 2nd, 2023
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. from sys import stdout
  2.  
  3. T = int(input())
  4. while T > 0:
  5.     T -= 1
  6.     n = int(input())
  7.     arr = list(map(int, input().split()))
  8.     pfs = [0]*1
  9.     for x in arr:
  10.         pfs.append(pfs[-1]+x)
  11.     l, r = 1, n
  12.     while l < r:
  13.         m = (l+r) // 2
  14.         print("?", m, end = " ")
  15.         for i in range(l, m+1):
  16.             print(i, end = " ")
  17.         print()
  18.         stdout.flush()
  19.         rps = int(input())
  20.         if rps == pfs[m] - pfs[l-1]:
  21.             l = m+1
  22.         else:
  23.             r = m
  24.     print("!", l, end = "\n")
  25.     stdout.flush()
  26.  
Advertisement
Add Comment
Please, Sign In to add comment