結果
問題 | No.1778 括弧列クエリ / Bracketed Sequence Query |
ユーザー | Wizist |
提出日時 | 2021-12-11 18:23:10 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,147 bytes |
コンパイル時間 | 1,378 ms |
コンパイル使用メモリ | 86,816 KB |
実行使用メモリ | 93,924 KB |
最終ジャッジ日時 | 2023-09-27 06:42:12 |
合計ジャッジ時間 | 31,077 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 998 ms
81,036 KB |
testcase_01 | AC | 1,025 ms
80,856 KB |
testcase_02 | AC | 983 ms
82,404 KB |
testcase_03 | AC | 1,280 ms
85,628 KB |
testcase_04 | AC | 1,117 ms
82,360 KB |
testcase_05 | AC | 833 ms
84,676 KB |
testcase_06 | AC | 635 ms
81,736 KB |
testcase_07 | AC | 236 ms
81,756 KB |
testcase_08 | AC | 1,483 ms
93,592 KB |
testcase_09 | AC | 365 ms
84,120 KB |
testcase_10 | AC | 811 ms
89,728 KB |
testcase_11 | AC | 702 ms
86,504 KB |
testcase_12 | AC | 879 ms
84,692 KB |
testcase_13 | TLE | - |
testcase_14 | AC | 782 ms
88,372 KB |
testcase_15 | AC | 72 ms
71,452 KB |
testcase_16 | AC | 1,430 ms
93,896 KB |
testcase_17 | AC | 1,382 ms
93,924 KB |
testcase_18 | AC | 1,441 ms
93,640 KB |
testcase_19 | TLE | - |
testcase_20 | AC | 1,407 ms
93,872 KB |
testcase_21 | AC | 72 ms
71,400 KB |
testcase_22 | AC | 71 ms
71,480 KB |
testcase_23 | TLE | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
ソースコード
from bisect import bisect_left def rmq_update(t, i, val, f=min): t[i + len(t) // 2] = val i = (i + len(t) // 2) // 2 while i > 0: t[i] = f(t[i * 2], t[i * 2 + 1]) i //= 2 def rmq_query(t, l, r, f=min, def_val=0x7fffffff): i, j, a, b = l + len(t) // 2, r + len(t) // 2, def_val, def_val while i < j: if i % 2 != 0: a = f(a, t[i]); i += 1 if j % 2 != 0: j -= 1; b = f(b, t[j]) i, j = i // 2, j // 2 return f(a, b) N, Q = map(int, input().split()) s = input().strip() p = [0] * N st = [] for i, x in enumerate(s): if x == '(': st.append(i) else: p[i] = st[-1] p[st[-1]] = i st.pop() a = [(i, p[i]) for i, x in enumerate(s) if x == '('] t1, t2 = [N] * (N * 2), [-1] * (N * 2) for i, x in enumerate(p): rmq_update(t1, i, x, min) rmq_update(t2, i, x, max) for _ in range(Q): x, y = map(int, input().split()) x -= 1; y -= 1 if x > y: x, y = y, x l = min(rmq_query(t1, x, y + 1, min, N), x) r = max(rmq_query(t2, x, y + 1, max, 0), y) i = bisect_left(a, (l, r)) while i < len(a) and i >= 0: if a[i][0] <= l and a[i][1] >= r: break i -= 1 if i < 0 or i >= len(a): print(-1) else: print(a[i][0] + 1, a[i][1] + 1)