結果
| 問題 |
No.833 かっこいい電車
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-08 14:35:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 193 ms / 2,000 ms |
| コード長 | 1,150 bytes |
| コンパイル時間 | 1,164 ms |
| コンパイル使用メモリ | 81,836 KB |
| 実行使用メモリ | 8,704 KB |
| 最終ジャッジ日時 | 2024-12-30 09:47:47 |
| 合計ジャッジ時間 | 5,933 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#include<iostream>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
struct BIT{
int n;
vector<ll> v;
BIT(int x) : n(x){
v.resize(n+1, 0);
}
void add(int x, int val){
while(x <= n){
v[x] += val;
x += x&-x;
}
}
ll query(int x){
ll ret = 0;
while(x > 0){
ret += v[x];
x -= x&-x;
}
return ret;
}
};
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+1, x);
}
set<int> fr;
for(int i = 1; i <= n+1; i++) fr.insert(i);
while(q-- > 0){
int a, b;
cin >> a >> b;
if(a == 1){
if(fr.count(b+1)){
fr.erase(b+1);
}
}else if(a == 2){
if(fr.count(b+1)==0){
fr.insert(b+1);
}
}else if(a == 3){
bit.add(b, 1);
}else if(a == 4){
cout << bit.query(*(fr.upper_bound(b))-1) - bit.query(*(--fr.upper_bound(b))-1) << endl;
}
}
return 0;
}