結果

問題 No.1222 -101
ユーザー 沙耶花沙耶花
提出日時 2020-09-04 23:29:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,481 bytes
コンパイル時間 2,165 ms
コンパイル使用メモリ 215,416 KB
実行使用メモリ 14,764 KB
最終ジャッジ日時 2024-05-05 03:41:56
合計ジャッジ時間 5,462 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 5 ms
5,632 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 WA -
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 WA -
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 55 ms
8,064 KB
testcase_35 AC 56 ms
7,936 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000	

template <typename T0,typename T1,typename F0,typename F1,typename F2>
struct lazysegtree{
	//元データx[i]はv[n+i]
	//v[i]の親はv[i/2],子はv[i*2]とv[i*2+1]
	F0 func0;
	F1 func1;
	F2 func2;
	vector<T0> v0;
	vector<T1> v1;
	int n;
	int cnt;
	
	T0 init_value0;
	T1 init_value1;
	
	lazysegtree(int sz,F0 f0,F1 f1,F2 f2,T0 iv0,T1 iv1):func0(f0),func1(f1),func2(f2){
		init_value0 = iv0;
		init_value1 = iv1;
		n=1;
		cnt=0;
		while(true){
			if(n>=sz)break;
			n*=2;
			cnt++;
		}
		v0.resize(2*n,init_value0);
		v1.resize(2*n,init_value1);
		
	}
	
	lazysegtree(vector<T0> &x,F0 f0,F1 f1,F2 f2,T0 iv0,T1 iv1):func0(f0),func1(f1),func2(f2){
		init_value0 = iv0;
		init_value1 = iv1;
		n=1;
		cnt=0;
		while(true){
			if(n>=x.size())break;
			n*=2;
			cnt++;
		}
		v0.resize(2*n,init_value0);
		v1.resize(2*n,init_value1);
		for(int i=0;i<x.size();i++){
			v0[n+i]=x[i];
		}
		for(int i=n-1;i>=0;i--){
			v0[i]=func0(v0[i<<1],v0[(i<<1)+1]);
		}	
	}

	//2人の子供に伝える
	void propagate(int ind){
		update(ind<<1,v1[ind]);
		update((ind<<1)+1,v1[ind]);
		v1[ind] = init_value1;
	}
	
	//あるノードに対し先祖から伝播	
	void reflect(int l,int r){
		int j = cnt;
		while(l>>j==r>>j&&j>=1){
			propagate(l>>j);
			j--;
		}
		for(;j>=1;j--){
			propagate(l>>j);
			propagate(r>>j);
		}
	}
	
	//子供の値を親に伝える
	void mergeChildren(int ind){
		v0[ind] = func1(func0(v0[ind<<1],v0[(ind<<1)+1]),v1[ind],n>>(31-__builtin_clz(ind)));
	}
	
	//ある要素について作用させる
	void update(int ind,T1 x){
		v0[ind] = func1(v0[ind],x,n>>(31-__builtin_clz(ind)));
		v1[ind] = func2(v1[ind],x);
	}
	
	//[l,r)に対して作用させる
	void update(int l,int r,T1 x){
		if(l>=r)return;
		int L = l,R = r;
		l+=n;
		r+=n;
		reflect(l,r-1);
		while(true){
			if(l&1){
				update(l,x);
				l++;
			}
			if(r&1){
				update(r-1,x);
				r--;
			}
			if(l>=r)break;
			l>>=1;
			r>>=1;
		}
		
		l = L + n;
		r = R + n-1;
		
		while(true){
			l>>=1;
			r>>=1;
			if(l<=0)break;

			if(l==r){
				while(true){
					mergeChildren(l);
					l>>=1;
					if(!l)return;
				}
			}
			else{
				mergeChildren(l);
				mergeChildren(r);
			}
		}
		
	}
	
	//区間[l,r)におけるクエリ処理
	T0 query(int l,int r){
		T0 res1 = init_value0;
		T0 res2 = init_value0;
		if(l>=r)return res1;
		l+=n;
		r+=n;
		reflect(l,r-1);
		while(true){
			if(l&1){
				res1=func0(res1,v0[l]);
				l++;
			}
			if(r&1){
				res2=func0(v0[r-1],res2);
				r--;
			}
			if(l>=r)break;
			l>>=1;
			r>>=1;
		}
		return func0(res1,res2);
	}

	void show(){
		int n = 1;
		for(int i=1;i<v0.size();i++){
			for(int j=0;j<n;j++){
				if(j!=0)cout<<' ';
				cout<<v0[i+j];
			}
			cout<<endl;
			i+=n-1;
			n*=2;
		}
	}
	
};


int main(){

	int N,M;
	cin>>N>>M;
	
	vector<int> L(M),R(M),P(M);
	for(int i=0;i<M;i++){
		scanf("%d %d %d",&L[i],&R[i],&P[i]);
		L[i]--;
		R[i]--;
	}
	
	vector<int> imos0(N+1,0),imos1(N+1,0),f(N+1,0);
	
	for(int i=0;i<M;i++){
		if(P[i]==0){
			imos1[L[i]]++;
			imos1[R[i]+1]--;
		}
		else{
			imos0[L[i]]++;
			imos0[R[i]+1]--;
			f[R[i]]=1;
		}
	}
	
	for(int i=1;i<N;i++){
		imos0[i]+=imos0[i-1];
		imos1[i]+=imos1[i-1];
	}
	
	int ans = 1;
	vector<int> Z;
	for(int i=0;i<N;i++){
		int a = imos0[i],b = imos1[i];
		if(a==0&&b==0)ans = mod(ans * 3);
		else if(a>0){
			if(f[i]==0)ans = mod(ans * 2);
		}
		else{
			Z.push_back(i);
		}
	}
	
	vector<pair<int,int>> X;
	for(int i=0;i<M;i++){
		if(P[i]==0){
			L[i] = distance(Z.begin(),lower_bound(Z.begin(),Z.end(),L[i]));
			R[i] = distance(Z.begin(),upper_bound(Z.begin(),Z.end(),R[i]));
			R[i]--;
			if(L[i]>R[i]){
				cout<<0<<endl;
				return 0;
			}
			X.emplace_back(R[i],L[i]);
		}
	}
	sort(X.begin(),X.end());
	
	int p = 0;
	
	auto f0 = [](int a,int b){
		if(a<0||b<0)return 0;
		return (int)mod(a+b);
	};
	
	auto f1 = [](int a,int b,long long sz){
		return max(-1,a+b);
	};
	
	auto f2 = [](int a,int b){
		return max(a+b,-modulo-1);
	};
	int l = 0;
	lazysegtree<int,int,decltype(f0),decltype(f1),decltype(f2)> seg(Z.size()+1,f0,f1,f2,0,0);
	seg.update(0,1,1);
	for(int i=1;i<=Z.size();i++){
		seg.update(i,i+1,seg.query(l,i));
		
		if(p!=X.size() && X[p].first == i-1){
			l = max(l,X[p].second+1);
			p++;
		}
	}
	
	ans = mod(ans * seg.query(l,1+Z.size()));
	
	cout<<ans<<endl;
	
	return 0;
}
0