結果
| 問題 | No.876 Range Compress Query |
| コンテスト | |
| ユーザー |
sigma425
|
| 提出日時 | 2019-09-09 19:50:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 128 ms / 2,000 ms |
| コード長 | 2,101 bytes |
| 記録 | |
| コンパイル時間 | 1,395 ms |
| コンパイル使用メモリ | 163,012 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-28 14:01:12 |
| 合計ジャッジ時間 | 3,484 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
o<<"{";
for(const T& v:vc) o<<v<<",";
o<<"}";
return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif
struct segtree{
using D = int;
int N;
vector<D> val;
segtree(){}
segtree(int n){
N=1;
while(N<n) N*=2;
val.assign(N*2,0);
}
segtree(const vector<D>& ds){
int n = ds.size();
N=1;
while(N<n) N*=2;
val.assign(N*2,0);
rep(i,n) val[i+N] = ds[i];
for(int i=N-1;i>0;i--) val[i] = val[i*2] + val[i*2+1];
}
void assign(int k,D d){
k+=N;
val[k]=d;
k/=2;
while(k){
val[k] = val[k*2] + val[k*2+1];
k/=2;
}
}
D sum(int a,int b){ //non-commutative & unrecursive
D res = 0;
a+=N,b+=N;
while(a<b){
if(a&1) res += val[a++];
if(b&1) res += val[--b];
a/=2,b/=2;
}
return res;
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false); //DON'T USE scanf/printf/puts !!
cout << fixed << setprecision(20);
int N,Q;
cin >> N >> Q;
V<ll> d(N-1);
segtree seg(N-1);
{
V<int> a(N);
rep(i,N) cin >> a[i];
rep(i,N-1) d[i] = a[i+1] - a[i];
rep(i,N-1) if(d[i] != 0) seg.assign(i,1);
}
rep(_,Q){
int t;
cin >> t;
if(t == 1){
int l,r,x;
cin >> l >> r >> x;
l--;
if(l){
d[l-1] += x;
seg.assign(l-1,(d[l-1] != 0));
}
if(r != N){
d[r-1] -= x;
seg.assign(r-1,(d[r-1] != 0));
}
}else{
int l,r;
cin >> l >> r;
cout << seg.sum(l-1,r-1)+1 << endl;
}
}
}
sigma425