結果
問題 | No.833 かっこいい電車 |
ユーザー |
|
提出日時 | 2020-06-18 21:05:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 129 ms / 2,000 ms |
コード長 | 2,009 bytes |
コンパイル時間 | 1,572 ms |
コンパイル使用メモリ | 172,900 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-03 12:58:29 |
合計ジャッジ時間 | 4,290 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=0;i<(int)(n);i++)using namespace std;using ll = long long ;using P = pair<int,int> ;using pll = pair<long long,long long>;constexpr int INF = 1e9;constexpr long long LINF = 1e17;constexpr int MOD = 1000000007;constexpr double PI = 3.14159265358979323846;//1-indexedに注意!!!struct BIT{int n;vector<long long> bit;BIT(int n):n(n){bit.resize(n+1);}long long sum(int i){long long res = 0;while(i > 0){res += bit[i];i -= i&-i;}return res;}void add(int i,long long val){while(i <= n){bit[i] += val;i += i&-i;}}};int main(){int n,q;cin >> n >> q;BIT l(n+1); rep(i,n) l.add(i+1,1);BIT r(n+1); rep(i,n) r.add(i+1,1);BIT S(n);vector<ll> a(n);rep(i,n){cin >> a[i];S.add(i+1,a[i]);}while(q--){int t,x;cin >> t >> x;if(t==1){int L = l.sum(x);int R = r.sum(x+1);int prevR = r.sum(x);int prevL = l.sum(x+1);r.add(L,R-prevR);r.add(x+1,-R+prevR);l.add(x+1,L-prevL);l.add(R+1,-L+prevL);}else if(t==2){int prevL = l.sum(x);int prevR = r.sum(x);r.add(prevL,x-prevR);r.add(x+1,-x+prevR);l.add(x+1,x+1-prevL);l.add(prevR+1,-x-1+prevL);}else if(t==3){S.add(x,1);}else if(t==4){int L = l.sum(x);int R = r.sum(x);if(L==1) cout << S.sum(R) << endl;else cout << S.sum(R) - S.sum(L-1) << endl;}/*cout << "start" << endl;rep(i,n) cout << l.sum(i+1) << " " ;cout << endl;rep(i,n) cout << r.sum(i+1) << " ";cout << endl;*/}return 0;}