結果
問題 | No.833 かっこいい電車 |
ユーザー |
![]() |
提出日時 | 2019-05-24 22:57:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 222 ms / 2,000 ms |
コード長 | 871 bytes |
コンパイル時間 | 670 ms |
コンパイル使用メモリ | 76,784 KB |
最終ジャッジ日時 | 2025-01-07 04:01:25 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
#include <iostream> #include <set> using namespace std; using ll = long long; ll n,q,t[200010] = {}; set<int> l,r; void built(){ for(int i = n-1;i>0;i--){ t[i] = t[i<<1] + t[i<<1|1]; } } void update(ll p,ll a){ for(t[p+=n] += a;p>1;p >>= 1){ t[p>>1] = t[p] + t[p^1]; } } ll query(int l, int r){ ll sum = 0; for(l += n, r += n; l<r; l >>= 1,r >>= 1){ if(l&1) sum += t[l++]; if(r&1) sum += t[--r]; } return sum; } int main(){ int i; cin >> n >> q; for(i=0;i<n;i++){ int a; cin >> a; t[i + n] = a; l.insert(-i); r.insert(i); } built(); for(i=0;i<q;i++){ int w,x; cin >> w >> x; x--; if(w==1){ r.erase(x); l.erase(-(x + 1)); } if(w==2){ r.insert(x); l.insert(-(x + 1)); } if(w==3){ update(x,1); } if(w==4){ int le = *l.lower_bound(-x); int ri = *r.lower_bound(x); cout << query(-le,ri + 1) << endl; } } }