結果

問題 No.876 Range Compress Query
ユーザー tko919tko919
提出日時 2019-09-07 03:22:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,588 bytes
コンパイル時間 1,479 ms
コンパイル使用メモリ 163,384 KB
実行使用メモリ 4,856 KB
最終ジャッジ日時 2023-09-07 08:39:43
合計ジャッジ時間 3,585 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 54 ms
4,440 KB
testcase_12 AC 46 ms
4,376 KB
testcase_13 AC 47 ms
4,380 KB
testcase_14 AC 55 ms
4,380 KB
testcase_15 AC 42 ms
4,484 KB
testcase_16 AC 54 ms
4,844 KB
testcase_17 AC 54 ms
4,656 KB
testcase_18 AC 56 ms
4,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

int bit[100010],n; //1-index
void add(int i,int a){
    i++;
    while(i<=n){
        bit[i]+=a;
        i+=(i&(-i));
    }
}
int sum(int i){
    int res=0; i++;
    while(i){
        res+=bit[i];
        i-=(i&(-i));
    }
    return res;
}

int main(){
    int q; scanf("%d%d",&n,&q);
    int a[100010],b[100010]; //階差
    rep(i,0,n){
        scanf("%d",&a[i]);
        if(i){
            b[i]=a[i]-a[i-1];
            if(b[i])add(i,1);
        }
    }
    int fl,l,r,ad;
    rep(rot,0,q){
        scanf("%d%d%d",&fl,&l,&r);
        if(fl==1){
            scanf("%d",&ad);
            if(l>1){
                if(b[l-1])add(l-1,-1);
                b[l-1]+=ad;
                if(b[l-1])add(l-1,1);
            }
            if(r<n){
                if(b[r])add(r,-1);
                b[r]-=ad;
                if(b[r])add(r,1);
            }
        }
        else{
            printf("%d\n",sum(r-1)-sum(l-1)+1);
        }
    }
    return 0;
}
0