結果

問題 No.876 Range Compress Query
ユーザー autumn-eelautumn-eel
提出日時 2019-09-06 21:38:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,312 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 176,336 KB
実行使用メモリ 7,500 KB
最終ジャッジ日時 2023-09-06 23:02:29
合計ジャッジ時間 5,063 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

struct st{
	int s,l,r;
};
enum SegtreeType{
	CUSTOM,
	RAQ_RMQ,
	RAQ_RSQ,
	RUQ_RMQ,
	RUQ_RSQ,
	RMQ_RMQ
};
template<SegtreeType ty,class T>
class LazySegtree{
	int n;
	vector<T>dat;
	vector<int>lazy;
	T INIT;
	T E0;
	int E1;
	function<T(T,int,int)>F0;
	function<int(int,int)>F1;
	function<T(T,T)>F2;
public:
	LazySegtree(int n_,T INIT,T E0,int E1
	,function<T(T,int,int)>F0,function<int(int,int)>F1,function<T(T,T)>F2):
		INIT(INIT),E0(E0),E1(E1),F0(F0),F1(F1),F2(F2){
		n=1;while(n<n_)n<<=1;
		dat=vector<T>(2*n);
		lazy=vector<int>(2*n);
		for(int i=0;i<2*n-1;i++){
			dat[i]=INIT;
			lazy[i]=E1;
		}
	}
	inline void push(int k,int s){
		if(lazy[k]==E1)return;
		dat[k]=F0(dat[k],lazy[k],s);
		if(k<n-1){
			lazy[k*2+1]=F1(lazy[k*2+1],lazy[k]);
			lazy[k*2+2]=F1(lazy[k*2+2],lazy[k]);
		}
		lazy[k]=E1;
	}
	inline void upnode(int k){
		dat[k]=F2(dat[k*2+1],dat[k*2+2]);
	}
	inline void update(int a,int b,int x,int k,int l,int r){
		push(k,r-l);
		if(r<=a||b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]=F1(lazy[k],x);
			push(k,r-l);
			return;
		}
		update(a,b,x,k*2+1,l,(l+r)/2);
		update(a,b,x,k*2+2,(l+r)/2,r);
		upnode(k);
	}
	inline T query(int a,int b,int k,int l,int r){
		push(k,r-l);
		if(b<=l||r<=a)return E0;
		if(a<=l&&r<=b)return dat[k];
		T lb=query(a,b,k*2+1,l,(l+r)/2);
		T rb=query(a,b,k*2+2,(l+r)/2,r);
		upnode(k);
		return F2(lb,rb);
	}
	inline void update(int a,int b,int x){
		update(a,b,x,0,0,n);
	}
	inline void update(int a,int x){
		update(a,a+1,x);
	}
	inline T query(int a,int b){
		return query(a,b,0,0,n);
	}
	inline T query(int a){
		return query(a,a+1);
	}
};
int main(){
	int n,q;cin>>n>>q;
	LazySegtree<CUSTOM,st>seg(n,{1,0,0},{0,-1,-1},0,
	[](st a,int b,int s){
		return (st){a.s,a.l+b,a.r+b};
	},
	[](int a,int b){
		return a+b;
	},
	[](st a,st b){
		return (st){a.s+b.s-(a.r==b.l),a.l,b.r};
	}
	);
	rep(i,n){
		int a;scanf("%d",&a);
		seg.update(i,a);
	}
	rep(i,q){
		int t;scanf("%d",&t);
		if(t==1){
			int l,r,x;scanf("%d%d%d",&l,&r,&x);l--;
			seg.update(l,r,x);
		}
		else{
			int l,r;scanf("%d%d",&l,&r);l--;
			printf("%d\n",seg.query(l,r).s);
		}
	}
}
0