結果

問題 No.833 かっこいい電車
ユーザー ttttan2ttttan2
提出日時 2019-05-25 00:18:51
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,944 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 149,936 KB
実行使用メモリ 17,836 KB
最終ジャッジ日時 2023-09-14 21:00:21
合計ジャッジ時間 8,464 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 2 ms
7,740 KB
testcase_02 AC 3 ms
7,756 KB
testcase_03 WA -
testcase_04 AC 3 ms
8,156 KB
testcase_05 AC 3 ms
8,100 KB
testcase_06 AC 3 ms
7,800 KB
testcase_07 AC 2 ms
7,796 KB
testcase_08 AC 3 ms
7,864 KB
testcase_09 AC 3 ms
7,820 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 45 ms
8,992 KB
testcase_16 AC 36 ms
8,984 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 35 ms
9,108 KB
testcase_20 AC 11 ms
8,160 KB
testcase_21 WA -
testcase_22 AC 58 ms
9,484 KB
testcase_23 AC 39 ms
8,780 KB
testcase_24 AC 59 ms
9,600 KB
testcase_25 WA -
testcase_26 AC 42 ms
9,644 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 59 ms
9,604 KB
testcase_31 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
vector<ll> pri;
void priinit(ll n){
    bool used[n+1];
    fill(used,used+n+1,false);
    rep(i,2,n+1){
        if(used[i]==false){
            pri.push_back(i);
            for(ll j=i;j<=n;j+=i)used[j]=true;
        }
    }
}
vector<ll> prisep(ll n){
    vector<ll> ret;
    rep(i,0,pri.size()){
        while(n%pri[i]==0){
            ret.push_back(pri[i]);
            n/=pri[i];
        }
    }
    return ret;
}

ll par[200010];
ll par2[200010];
void init(ll n){
    for(int i=0;i<n;i++){
        par[i]=i;
        par2[i]=i;
    }
}
ll root(ll n){
    if(par[n]==n)return n;
    return par[n]=root(n+1);
}
ll roo(ll n){
    if(par[n]==n)return n;
    return par[n]=roo(par[n]);
}
ll root2(ll n){
    if(par2[n]==n)return n;
    return par2[n]=root2(n-1);
}
ll roo2(ll n){
    if(par2[n]==n)return n;
    return par2[n]=roo2(par2[n]);
}
void unit(ll a,ll b){
    a=root(a);
    b=root(b);
    if(a==b)return;
    if(a<b){
        par[a]=b;
    }
    else par[b]=a;
    a=root2(a);
    b=root2(b);
    if(a<b){
        par2[b]=a;
        
    }
    else par2[a]=b;
}
void sepa(ll a,ll b){
    if(a<b){
        par[a]=a;
        par2[b]=b;
    }
    else{
        par[b]=b;
        par2[a]=a;
    }
    
}
ll bit[400010];
ll u;
void bitinit(ll n){
    rep(i,0,69){
        ll y=pow(2,i);
        if(y>=n){
            u=y;
            break;
        }
    }
    fill(bit,bit+u+10,0);
}
void add(ll n,ll x){
    ll i=n;
    bit[i]+=x;
    while(i<u){
        i+=i&(-i);
        bit[i]+=x;
    }
}
ll sum(ll n){
    ll i=n;
    ll ret=0;
    while(i>0){
        ret+=bit[i];
        i-=i&(-i);
    }
    return ret;
}
int main(){
    ll n,q;cin>>n>>q;
    ll a[n];rep(i,0,n)cin>>a[i];
    init(n+1);
    bitinit(n+1);
    rep(i,0,n)add(i+1,a[i]);
    ll k=0;
    rep(i,0,q){
        ll c,x;cin>>c>>x;
        if(c==1){
            unit(x,x+1);
            k=0;
        }
        if(c==2){
            sepa(x,x+1);
            k=0;
        }
        if(c==3){
            add(x,1);
        }
        if(c==4){
            ll l;
            ll r;
            k++;
            if(k>=2){
                l=roo2(x);
                r=roo(x);
           }
           else{
                l=root2(x);
                r=root(x);
            }
            //cout<<l<<" "<<r<<endl;
            ll e=sum(r)-sum(l-1);
            cout<<e<<endl;
        }
        //cout<<root(2)<<" "<<root2(2)<<endl;
    }
    //cout<<par2[1]<<" "<<par2[2]<<endl;
}
0