結果

問題 No.833 かっこいい電車
コンテスト
ユーザー 卢泓希
提出日時 2026-02-20 16:00:44
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,555 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,184 ms
コンパイル使用メモリ 219,760 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2026-02-20 16:00:51
合計ジャッジ時間 6,220 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define fi first
#define sc second
#define pii pair<int,int>
#define pdd pair<double,double>
#define pb push_back
#define umap unordered_map
#define mset multiset
#define pq priority_queue
#define ull unsigned long long
#define i128 __int128
#define ld long double
#define fixs fixed<<setprecision
#define FileIn(x) freopen(x".in","r",stdin)
#define FileOut(x) freopen(x".out","w",stdout)
#define FileIO(x) FileIn(x),FileOut(x);
const int maxn=1e6+10;
int lb(int x){
    return x&(-x);
}
struct BIT{
    int c[maxn],N;
    void init(int n){
        N=n;
        for(int i=1;i<=n;i++) c[i]=0;
    }
    void upd(int x,int k){
        for(;x<=N;x+=lb(x)) c[x]+=k;
    }
    int query(int x){
        int sum=0;
        for(;x;x-=lb(x)) sum+=c[x];
        return sum;
    }
}tr;
int n,q;
set<int> s;
void solve(){
    cin>>n>>q,tr.init(n);
    for(int i=0;i<=n;i++) s.insert(i);
    for(int i=1,x;i<=n;i++) cin>>x,tr.upd(i,x);
    while(q--){
        int op,x;
        cin>>op>>x;
        if(op==1) s.erase(x);
        if(op==2) s.insert(x);
        if(op==3) tr.upd(x,1);
        if(op==4){
            auto r=s.lower_bound(x),l=r;
            l--;
            cout<<tr.query(*r)-tr.query(*l)<<endl;
        }
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}
/*
Samples
input:

output:

THINGS TODO:
检查freopen,尤其是后缀名
检查空间
检查调试语句是否全部注释
*/
0