結果
問題 |
No.833 かっこいい電車
|
ユーザー |
|
提出日時 | 2019-05-25 16:40:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 161 ms / 2,000 ms |
コード長 | 991 bytes |
コンパイル時間 | 744 ms |
コンパイル使用メモリ | 82,192 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2024-07-02 03:53:18 |
合計ジャッジ時間 | 4,329 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <set> using namespace std; struct BIT { vector<long long> S; BIT(int n) : S(n + 1) {} void add(int k, long long v) { for (int i = k + 1; i < S.size(); i += i & -i) { S[i] += v; } } long long sum(int k) { long long res = 0; for (int i = k; i > 0; i -= i & -i) { res += S[i]; } return res; } }; int main() { int n, q; cin >> n >> q; BIT bit(n); for (int i = 0; i < n; i++) { int x; cin >> x; bit.add(i, x); } set<int> st; for (int i = 0; i <= n; i++) { st.insert(i); } while (q--) { int type, x; cin >> type >> x; x--; if (type == 1) { st.erase(x+1); } else if (type == 2) { st.insert(x+1); } else if (type == 3) { bit.add(x, 1); } else { int r = *st.upper_bound(x); int l = *prev(st.upper_bound(x)); cout << bit.sum(r) - bit.sum(l) << '\n'; } } }