結果

問題 No.876 Range Compress Query
ユーザー 0214sh70214sh7
提出日時 2019-09-06 22:39:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 1,996 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 166,184 KB
実行使用メモリ 12,732 KB
最終ジャッジ日時 2023-09-07 01:34:12
合計ジャッジ時間 4,381 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,468 KB
testcase_01 AC 4 ms
5,468 KB
testcase_02 AC 3 ms
5,444 KB
testcase_03 AC 4 ms
7,528 KB
testcase_04 AC 2 ms
7,460 KB
testcase_05 AC 2 ms
7,568 KB
testcase_06 AC 3 ms
5,616 KB
testcase_07 AC 3 ms
7,548 KB
testcase_08 AC 3 ms
7,544 KB
testcase_09 AC 3 ms
5,652 KB
testcase_10 AC 3 ms
7,608 KB
testcase_11 AC 209 ms
12,568 KB
testcase_12 AC 174 ms
12,340 KB
testcase_13 AC 173 ms
12,608 KB
testcase_14 AC 206 ms
12,556 KB
testcase_15 AC 149 ms
11,564 KB
testcase_16 AC 202 ms
12,500 KB
testcase_17 AC 200 ms
12,732 KB
testcase_18 AC 215 ms
12,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << -1 << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
    
const int MAX_N=200010;
int n,dat[4*MAX_N-1];
int Seg_init(int n_){
    n=1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;++i)dat[i]=0;
    return n;
}
int Seg_calc(int a,int b){
    return a+b;
}
void Seg_update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
        k=(k-1)/2;
        dat[k]=Seg_calc(dat[2*k+1],dat[2*k+2]);
    }
}
int Seg_query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l)return 0;
    if(a<=l&&r<=b)return dat[k];
    int vl=Seg_query(a,b,2*k+1,l,(l+r)/2);
    int vr=Seg_query(a,b,2*k+2,(l+r)/2,r);
    return Seg_calc(vl,vr);
}



signed main(void){
    
    int N,Q;
    int A[114514];
    int B[114514];
    int h[114514],l[114514],r[114514],x[114514];
    cin >> N >> Q;
    REP(i,N){
        cin >> A[i];
    }
    REP(i,N-1){
        B[i]=A[i+1]-A[i];
    }
    
    //REP(i,N-1){cout << B[i] << " ";}cout << endl;
    
    REP(i,Q){
        cin >> h[i];
        if(h[i]==1){
            cin >> l[i] >> r[i] >> x[i];
        }else{
            cin >> l[i] >> r[i];
            x[i]=114514;
        }
        l[i]--;r[i]--;
    }
    N--;
    
    int M = Seg_init(N);
    REP(i,N){
        Seg_update(i,B[i]==0?0:1);
    }
    
    REP(i,Q){
        if(h[i]==1){
            B[l[i]-1]+=x[i];
            B[r[i]]-=x[i];
            Seg_update(l[i]-1,B[l[i]-1]==0?0:1);
            Seg_update(r[i],B[r[i]]==0?0:1);
        }else{
            cout << Seg_query(l[i],r[i],0,0,M)+1 << endl;
        }
    }
    //REP(i,N){cout << B[i] << " ";}cout << endl;
    
  return 0;
}

0