結果
問題 | No.1802 Range Score Query for Bracket Sequence |
ユーザー |
👑 ![]() |
提出日時 | 2022-01-07 22:21:58 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,209 bytes |
コンパイル時間 | 2,530 ms |
コンパイル使用メモリ | 110,928 KB |
最終ジャッジ日時 | 2025-01-27 09:35:34 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 7 WA * 17 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <atcoder/fenwicktree> using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int N,Q; cin >> N >> Q; string S; cin >> S; atcoder::fenwick_tree<int> A(N); rep(i,N-1) if(S[i] == '(' && S[i+1] == ')') A.add(i,1); rep(i,Q){ int t; cin >> t; if(t == 2){ int l,r; cin >> l >> r; l--; int ans = A.sum(l,r-1); cout << ans << "\n"; } if(t == 1){ int p; cin >> p; p--; if(S[p] == '('){ if(p != N-1 && S[p+1] == ')') A.add(p, -1); S[p] = ')'; if(p != 0 && S[p-1] == '(') A.add(p-1, 1); } if(S[p] == ')'){ if(p != 0 && S[p-1] == '(') A.add(p-1, -1); S[p] = '('; if(p != N-1 && S[p+1] == ')') A.add(p, 1); } } } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;