結果
| 問題 | No.833 かっこいい電車 |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-02-19 21:53:28 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 2,000 ms |
| コード長 | 1,306 bytes |
| 記録 | |
| コンパイル時間 | 3,364 ms |
| コンパイル使用メモリ | 342,468 KB |
| 実行使用メモリ | 9,088 KB |
| 最終ジャッジ日時 | 2026-02-19 21:53:35 |
| 合計ジャッジ時間 | 6,669 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int MAXN = 1e5 + 5;
int n, q;
set<int> st;
struct BinaryIndexedTree {
int tr[MAXN];
void update(int p, int x) {
while (p <= n) {
tr[p] += x;
p += p & -p;
}
}
int query(int p) {
int res = 0;
while (p) {
res += tr[p];
p -= p & -p;
}
return res;
}
} BIT;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> q;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
BIT.update(i, x);
st.insert(i);
}
while (q--) {
int op, x;
cin >> op >> x;
if (op == 1) {
st.erase(x + 1);
} else if (op == 2) {
st.insert(x + 1);
} else if (op == 3) {
BIT.update(x, 1);
} else {
auto it = st.upper_bound(x);
int l, r;
if (it == st.end()) {
r = n;
it--;
l = *it;
} else {
r = *it - 1;
it--;
l = *it;
}
cout << BIT.query(r) - BIT.query(l - 1) << '\n';
}
}
return 0;
}
vjudge1