結果

問題 No.833 かっこいい電車
ユーザー ttttan2ttttan2
提出日時 2019-05-25 00:09:50
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,320 bytes
コンパイル時間 1,946 ms
コンパイル使用メモリ 146,524 KB
実行使用メモリ 9,800 KB
最終ジャッジ日時 2023-09-14 21:00:06
合計ジャッジ時間 12,379 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 WA -
testcase_02 AC 2 ms
7,808 KB
testcase_03 WA -
testcase_04 AC 2 ms
8,112 KB
testcase_05 AC 2 ms
8,120 KB
testcase_06 AC 2 ms
7,812 KB
testcase_07 WA -
testcase_08 AC 2 ms
7,536 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 11 ms
8,384 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 43 ms
9,392 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
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;
}
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 root2(ll n){
    if(par2[n]==n)return n;
    return par2[n]=root2(n-1);
}
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);
        }
        if(c==2){
            sepa(x,x+1);
        }
        if(c==3){
            add(x,1);
            k=1;
        }
        if(c==4){
            ll l;
            ll r;
            if(k==0){
                l=par2[x];
                r=par[x];
            }
            else{
                l=root2(x);
                r=root(x);
            }
            k=0;
            ll e=sum(r)-sum(l-1);
            cout<<e<<endl;
        }
        //cout<<root(2)<<" "<<root2(2)<<endl;
    }
    //cout<<par2[1]<<" "<<par2[2]<<endl;
}
0