結果

問題 No.876 Range Compress Query
ユーザー umezoumezo
提出日時 2024-03-05 06:13:13
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 905 bytes
コンパイル時間 6,249 ms
コンパイル使用メモリ 308,864 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-05 06:13:26
合計ジャッジ時間 11,648 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 RE -
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 2 ms
6,548 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 58 ms
6,548 KB
testcase_12 AC 47 ms
6,548 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;

int op(ll x,ll y){return x+y;}
int e(){return 0;}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n,q;
  cin>>n>>q;
  vector<ll> A(n),B(n);
  rep(i,n) cin>>A[i];
  for(int i=1;i<n;i++) B[i]=A[i]-A[i-1];
  segtree<int,op,e> seg(n);
  for(int i=1;i<n;i++) if(B[i]!=0) seg.set(i,1);
  while(q--){
    int c;
    cin>>c;
    if(c==1){
      int l,r;
      ll x;
      cin>>l>>r>>x;
      l--,r;
      if(B[l]==0) seg.set(l,1);
      B[l]+=x;
      if(B[l]==0) seg.set(l,0);
      if(B[r]==0) seg.set(r,1);
      B[r]-=x;
      if(B[r]==0) seg.set(r,0);
    }
    else{
      int l,r;
      cin>>l>>r;
      l--,r--;
      cout<<1+seg.prod(l+1,r+1)<<'\n';
    }
  }
    
  return 0;
}
0