結果
| 問題 | No.1802 Range Score Query for Bracket Sequence |
| コンテスト | |
| ユーザー |
Forested
|
| 提出日時 | 2022-01-07 12:11:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,239 bytes |
| コンパイル時間 | 777 ms |
| コンパイル使用メモリ | 74,176 KB |
| 最終ジャッジ日時 | 2025-01-27 08:58:37 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 WA * 17 |
ソースコード
#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*/ n);
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*/ r) << '\n';
}
}
}
Forested