結果
| 問題 | No.833 かっこいい電車 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-23 20:45:41 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,563 bytes |
| 記録 | |
| コンパイル時間 | 1,350 ms |
| コンパイル使用メモリ | 83,704 KB |
| 実行使用メモリ | 9,216 KB |
| 最終ジャッジ日時 | 2026-02-23 20:45:47 |
| 合計ジャッジ時間 | 3,722 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 WA * 20 |
ソースコード
#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 {
int 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() {
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;
}