結果

問題 No.876 Range Compress Query
ユーザー umezo
提出日時 2024-03-05 06:17:37
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 5,113 ms
コンパイル使用メモリ 310,064 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-29 17:47:55
合計ジャッジ時間 6,023 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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(r<n){
        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