結果

問題 No.876 Range Compress Query
ユーザー tjaketjake
提出日時 2019-09-07 08:51:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 2,374 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 5,732 KB
最終ジャッジ日時 2023-09-08 09:55:48
合計ジャッジ時間 4,479 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 192 ms
5,336 KB
testcase_12 AC 165 ms
5,172 KB
testcase_13 AC 161 ms
5,300 KB
testcase_14 AC 190 ms
5,316 KB
testcase_15 AC 137 ms
5,332 KB
testcase_16 AC 182 ms
5,732 KB
testcase_17 AC 186 ms
5,680 KB
testcase_18 AC 196 ms
5,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 100005

class BIT {
  int n;
  ll data[N];

public:
  BIT(int n) : n(n) {
    for(int i = 0; i < n+2; ++i) data[i] = 0;
  }
  void add(int k, ll x) {
    while(k <= n) {
      data[k] += x;
      k += k & -k;
    }
  }

  ll get(int k) {
    ll s = 0;
    while(k) {
      s += data[k];
      k -= k & -k;
    }
    return s;
  }
};

ll b[N], a[N];

int main() {
  int n, q;
  cin >> n >> q;
  rep(i, n) cin >> a[i];
  BIT bit(n+1);
  b[0] = a[0];
  rep(i, n-1) {
    b[i+1] = a[i+1] - a[i];
    if(b[i+1] != 0) bit.add(i+2, +1);
  }

  while(q--) {
    int t, l, r; ll x;
    cin >> t >> l >> r;
    switch(t) {
      case 1:
        cin >> x;
        if(x == 0) continue;
        if(b[l-1] != 0) bit.add(l, -1);
        b[l-1] += x;
        if(b[l-1] != 0) bit.add(l, +1);

        if(b[r] != 0) bit.add(r+1, -1);
        b[r] -= x;
        if(b[r] != 0) bit.add(r+1, +1);
        break;
      case 2:
        cout << 1 + (bit.get(r) - bit.get(l)) << endl;
        break;
    }
  }

  return 0;
}
0