結果

問題 No.876 Range Compress Query
ユーザー ttttan2ttttan2
提出日時 2019-09-06 22:26:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,525 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 148,784 KB
実行使用メモリ 4,396 KB
最終ジャッジ日時 2023-09-07 01:07:51
合計ジャッジ時間 3,780 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,388 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 139 ms
4,380 KB
testcase_12 AC 117 ms
4,384 KB
testcase_13 AC 115 ms
4,380 KB
testcase_14 AC 137 ms
4,376 KB
testcase_15 AC 95 ms
4,384 KB
testcase_16 AC 142 ms
4,380 KB
testcase_17 AC 143 ms
4,396 KB
testcase_18 AC 153 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
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 gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll dat[800010];
ll u;
void seginit(ll n){
    ll y=1;
    for(int i=0;;i++){
        
        if(y>=n){
            u=y;
            break;
        }
        y*=2;
    }
    fill(dat,dat+2*u,inf);
}
void add(ll n,ll x){
    ll i=n+u-1;
    dat[i]=x;
    while(i>0){
        i=(i-1)/2;
        dat[i]=min(dat[2*i+1],dat[i*2+2]);
    }
}
ll que(ll a,ll b,ll k,ll l,ll r){
    if(a>=r||b<=l)return inf;
    if(a<=l&&b>=r)return dat[k];
    ll m1=que(a,b,2*k+1,l,(l+r)/2);
    ll m2=que(a,b,2*k+2,(l+r)/2,r);
    return min(m1,m2);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,q;cin>>n>>q;
    ll a[n];
    ll r=sqrt(n);
    ll t=ceil((double)n/r);
    ll d[t];
    ll zou[t];
    fill(zou,zou+t,0);
    rep(i,0,n){
        cin>>a[i];
    }
    rep(i,0,t){
        ll cnt=0;
        rep(j,i*r,min(n,(i+1)*r)-1){
            if(a[j]!=a[j+1])cnt++;
        }
        d[i]=cnt;
    }
    rep(i,0,q){
        ll e;cin>>e;
        if(e==1){
            ll l,rr,x;cin>>l>>rr>>x;
            l--;rr--;
            ll b=l/r;
            ll c=rr/r;
            rep(j,b+1,c){
                zou[j]+=x;
            }
            if(b==c){
                rep(j,l,rr+1)a[j]+=x;
                
            }
            else{
                rep(j,l,(b+1)*r)a[j]+=x;
                rep(j,c*r,rr+1)a[j]+=x;
                
            }
            if(l%r!=0){
                if(a[l]==a[l-1])d[b]--;
                if(a[l]-x==a[l-1])d[b]++;
            }
            if(rr%r<r-1&&rr<n-1){
                if(a[r]==a[r+1])d[c]--;
                if(a[r]-x==a[r+1])d[c]++;
            }
        }
        else{
            ll l,rr;cin>>l>>rr;
            l--;
            rr--;
            ll b=l/r;
            ll c=rr/r;
            ll ans=1;
            if(b==c){
                rep(j,l,rr){
                    if(a[j]!=a[j+1])ans++;
                }
            }
            else{
                rep(j,l,(b+1)*r-1){
                    if(a[j]!=a[j+1])ans++;
                }
                rep(j,b+1,c+1){
                    ll sa=a[j*r];
                    ll sb=a[j*r-1];
                    sa+=zou[j];
                    sb+=zou[j-1];
                    if(sa!=sb)ans++;
                    if(j<c)ans+=d[j];
                    else{
                        rep(k,c*r,rr){
                            if(a[k]!=a[k+1])ans++;
                        }
                    }
                }
                
                
            }
            cout<<ans<<endl;
        }
    }
}
0