結果

問題 No.1778 括弧列クエリ / Bracketed Sequence Query
ユーザー Wizist
提出日時 2021-12-11 18:00:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 486 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 82,008 KB
実行使用メモリ 93,876 KB
最終ジャッジ日時 2024-07-20 00:30:37
合計ジャッジ時間 28,439 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 13 TLE * 6 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left

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 == '(']

for _ in range(Q):
	x, y = map(int, input().split())
	x -= 1; y -= 1
	i = bisect_left(a, (x, y))
	while i >= 0:
		if a[i][0] <= x and a[i][1] >= y: break
		i -= 1
	if i < 0: print(-1)
	else: print(a[i][0] + 1, a[i][1] + 1)
0