結果
| 問題 | No.833 かっこいい電車 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-23 20:51:07 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 2,000 ms |
| コード長 | 1,641 bytes |
| 記録 | |
| コンパイル時間 | 791 ms |
| コンパイル使用メモリ | 84,920 KB |
| 実行使用メモリ | 9,600 KB |
| 最終ジャッジ日時 | 2026-02-23 20:51:11 |
| 合計ジャッジ時間 | 3,657 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
typedef long long LL;
const int N = 100010;
int n, q, a[N];
set<int> s;
struct BIT {
LL tr[N];
int LowBit(int x) { return x & -x; };
void Add(int x, int v) {
for (int i = x; i <= n; i += LowBit(i)) {
tr[i] += v;
}
}
LL Sum(int x) {
LL ret = 0LL;
for (int i = x; i > 0; i -= LowBit(i)) {
ret += tr[i];
}
return ret;
}
};
BIT bit;
int main() {
// freopen("bus.in", "r", stdin);
// freopen("bus.out", "w", stdout);
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
bit.Add(i, a[i]);
if (i < n) s.insert(i);
}
while (q--) {
int op, x;
scanf("%d%d", &op, &x);
if (op == 1) {
s.erase(x);
} else if (op == 2) {
s.insert(x);
} else if (op == 3) {
bit.Add(x, 1);
} else {
if (s.empty()) printf("%lld\n", bit.Sum(n));
else {
auto r = s.lower_bound(x);
if (r == s.end()) {
auto l = r;
--l;
printf("%lld\n", bit.Sum(n) - bit.Sum(*l));
} else if (r == s.begin()) {
printf("%lld\n", bit.Sum(*r));
} else {
LL ans = bit.Sum(*r);
auto l = r;
--l;
ans -= bit.Sum(*l);
printf("%lld\n", ans);
}
}
}
}
return 0;
}