結果
問題 | No.2978 Lexicographically Smallest and Largest Subarray |
ユーザー |
|
提出日時 | 2024-12-03 21:11:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 267 ms / 2,000 ms |
コード長 | 1,182 bytes |
コンパイル時間 | 458 ms |
コンパイル使用メモリ | 81,776 KB |
実行使用メモリ | 84,476 KB |
平均クエリ数 | 1499.00 |
最終ジャッジ日時 | 2024-12-03 21:11:39 |
合計ジャッジ時間 | 18,000 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 57 |
ソースコード
import sys input = lambda: sys.stdin.readline().rstrip() def main(): # 入力 N, Q = map(int, input().split()) # 計算・出力 # count = [] def ask(l1, l2): # count.append(0) # [l1, N] < [l2, N] か? print(f'? {l1} {N} {l2} {N}', flush=True) res = int(input()) # res = 1 assert res != -1 return res def answer(l1, l2): # print(len(count)) print(f'! {l1} {l1} {l2} {N}', flush=True) exit() def solve(L, mode=0): # mode 0: 小さい方 while len(L) != 1: nL = [] while len(L) >= 2: a = L.pop() b = L.pop() res = ask(a, b) if res ^ mode: nL.append(a) else: nL.append(b) L += nL return L[0] lowL, highL = [], [] for i in range(1, N+1, 2): res = ask(i, i+1) if res: lowL.append(i) highL.append(i+1) else: lowL.append(i+1) highL.append(i) answer(solve(lowL, 0), solve(highL, 1)) if __name__ == "__main__": main()