結果
| 問題 | No.1802 Range Score Query for Bracket Sequence |
| コンテスト | |
| ユーザー |
Forested
|
| 提出日時 | 2021-11-20 11:56:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 524 ms / 2,000 ms |
| コード長 | 1,211 bytes |
| コンパイル時間 | 771 ms |
| コンパイル使用メモリ | 73,672 KB |
| 最終ジャッジ日時 | 2025-01-25 21:28:01 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 |
ソースコード
#include <iostream>
#include <string>
#include <atcoder/fenwicktree>
using namespace std;
using namespace atcoder;
int main() {
int n, q;
cin >> n >> q;
string s;
cin >> s;
fenwick_tree<int> ft(n - 1);
for (int i = 0; i < n - 1; ++i) {
if (s[i] == '(' && s[i + 1] == ')') {
ft.add(i, 1);
}
}
for (int qi = 0; qi < q; ++qi) {
int type;
cin >> type;
if (type == 1) {
int i;
cin >> i;
--i;
if (i != 0 && s[i - 1] == '(' && s[i] == ')') {
ft.add(i - 1, -1);
}
if (i != n - 1 && s[i] == '(' && s[i + 1] == ')') {
ft.add(i, -1);
}
if (s[i] == '(') {
s[i] = ')';
} else {
s[i] = '(';
}
if (i != 0 && s[i - 1] == '(' && s[i] == ')') {
ft.add(i - 1, 1);
}
if (i != n - 1 && s[i] == '(' && s[i + 1] == ')') {
ft.add(i, 1);
}
} else {
int l, r;
cin >> l >> r;
--l;
cout << ft.sum(l, r - 1) << '\n';
}
}
}
Forested