結果
問題 | No.833 かっこいい電車 |
ユーザー | veqcc |
提出日時 | 2019-05-24 23:39:47 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 83 ms / 2,000 ms |
コード長 | 1,750 bytes |
コンパイル時間 | 1,169 ms |
コンパイル使用メモリ | 112,412 KB |
実行使用メモリ | 9,912 KB |
最終ジャッジ日時 | 2023-09-14 20:58:03 |
合計ジャッジ時間 | 3,691 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
6,616 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 58 ms
6,840 KB |
testcase_11 | AC | 83 ms
8,820 KB |
testcase_12 | AC | 25 ms
5,792 KB |
testcase_13 | AC | 15 ms
4,380 KB |
testcase_14 | AC | 68 ms
8,876 KB |
testcase_15 | AC | 33 ms
6,232 KB |
testcase_16 | AC | 31 ms
7,040 KB |
testcase_17 | AC | 17 ms
4,376 KB |
testcase_18 | AC | 67 ms
6,692 KB |
testcase_19 | AC | 29 ms
6,644 KB |
testcase_20 | AC | 9 ms
4,380 KB |
testcase_21 | AC | 48 ms
4,872 KB |
testcase_22 | AC | 51 ms
9,332 KB |
testcase_23 | AC | 33 ms
6,996 KB |
testcase_24 | AC | 51 ms
9,256 KB |
testcase_25 | AC | 63 ms
6,500 KB |
testcase_26 | AC | 36 ms
8,032 KB |
testcase_27 | AC | 49 ms
6,380 KB |
testcase_28 | AC | 32 ms
4,536 KB |
testcase_29 | AC | 42 ms
5,972 KB |
testcase_30 | AC | 59 ms
9,912 KB |
testcase_31 | AC | 42 ms
6,664 KB |
ソースコード
#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <string> #include <vector> #include <random> #include <bitset> #include <queue> #include <cmath> #include <stack> #include <set> #include <map> typedef long long ll; using namespace std; const ll MOD = 1000000007LL; struct SegmentTree { private: int n; vector <ll> node; public: SegmentTree(int sz) { n = 1; while (n < sz) n *= 2; node.resize(2*n-1, 0); } void add(int x, int val) { x += n - 1; node[x] += val; while (x > 0) { x = (x - 1) / 2; node[x] = node[2*x+1] + node[2*x+2]; } } ll getsum(int a, int b, int k=0, int l=0, int r=-1) { if (r < 0) r = n; if (r <= a || b <= l) return 0; if (a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2*k+1, l, (l+r)/2); ll vr = getsum(a, b, 2*k+2, (l+r)/2, r); return vl + vr; } }; int main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, Q; cin >> n >> Q; SegmentTree seg(n); for (int i = 0; i < n; i++) { int A; cin >> A; seg.add(i, A); } set <int> st; for (int i = 0; i <= n; i++) st.insert(i); for (int q = 0; q < Q; q++) { int query, x; cin >> query >> x; if (query == 1) { st.erase(x); } else if (query == 2) { st.insert(x); } else if (query == 3) { seg.add(x - 1, 1); } else { auto itr = st.lower_bound(x); int r = *itr; itr--; int l = *itr; cout << seg.getsum(l, r) << "\n"; } } return 0; }