結果

問題 No.1222 -101
ユーザー leaf_1415leaf_1415
提出日時 2020-09-04 22:42:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 3,047 bytes
コンパイル時間 2,798 ms
コンパイル使用メモリ 88,468 KB
実行使用メモリ 19,180 KB
最終ジャッジ日時 2023-08-17 20:23:21
合計ジャッジ時間 9,407 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
15,464 KB
testcase_01 AC 8 ms
15,324 KB
testcase_02 AC 7 ms
11,188 KB
testcase_03 AC 7 ms
15,468 KB
testcase_04 AC 7 ms
11,420 KB
testcase_05 AC 8 ms
15,304 KB
testcase_06 AC 8 ms
15,284 KB
testcase_07 AC 8 ms
15,280 KB
testcase_08 AC 8 ms
15,456 KB
testcase_09 AC 8 ms
15,328 KB
testcase_10 AC 147 ms
15,544 KB
testcase_11 AC 147 ms
11,492 KB
testcase_12 AC 267 ms
19,136 KB
testcase_13 AC 266 ms
19,120 KB
testcase_14 AC 269 ms
19,104 KB
testcase_15 AC 206 ms
17,252 KB
testcase_16 AC 238 ms
17,984 KB
testcase_17 AC 259 ms
18,832 KB
testcase_18 AC 205 ms
17,120 KB
testcase_19 AC 221 ms
17,508 KB
testcase_20 AC 242 ms
18,220 KB
testcase_21 AC 242 ms
18,136 KB
testcase_22 AC 7 ms
15,432 KB
testcase_23 AC 8 ms
15,456 KB
testcase_24 AC 8 ms
15,440 KB
testcase_25 AC 7 ms
15,436 KB
testcase_26 AC 8 ms
15,304 KB
testcase_27 AC 7 ms
15,328 KB
testcase_28 AC 6 ms
11,380 KB
testcase_29 AC 7 ms
15,284 KB
testcase_30 AC 8 ms
15,552 KB
testcase_31 AC 7 ms
15,356 KB
testcase_32 AC 400 ms
19,136 KB
testcase_33 AC 402 ms
19,144 KB
testcase_34 AC 251 ms
19,072 KB
testcase_35 AC 257 ms
19,144 KB
testcase_36 AC 184 ms
19,084 KB
testcase_37 AC 179 ms
19,112 KB
testcase_38 AC 181 ms
19,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;

// range-add, range-min query
 
struct LazySegTree{
	int size;
	vector<llint> seg, delay;
	
	LazySegTree(){}
	LazySegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
		delay.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++){
			seg[i] = 0;
			delay[i] = 1;
		}
	}
	
	void eval(int l, int r, int k)
	{
		if(delay[k] != 1){
			seg[k] *= delay[k], seg[k] %= mod;  //総和クエリのときは区間幅を乗じる必要がある
			if(l < r){
				delay[k*2] *= delay[k], delay[k*2] %= mod;
				delay[k*2+1] *= delay[k], delay[k*2+1] %= mod;
			}
			delay[k] = 1;
		}
	}
	
	void update(int i, llint val)
	{
		int l = 0, r = (1<<size)-1, k = 1;
		eval(l, r, k);
		for(int j = size-1; j >= 0; j--){
			k <<= 1;
			if(i & (1<<j)){
				k++;
				r = (l+r)/2;
			}
			else l = (l+r)/2+1;
			eval(l, r, k);
		}
		
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = (seg[i*2] + seg[i*2+1]) % mod;
		}
	}
	
	void add(int a, int b, int k, int l, int r, llint val)
	{
		eval(l, r, k);
		
		if(b < l || r < a) return;
		if(a <= l && r <= b){
			delay[k] *= val, delay[k] %= mod;
			eval(l, r, k);
			return;
		}
		add(a, b, k*2, l, (l+r)/2, val);
		add(a, b, k*2+1, (l+r)/2+1, r, val);
		seg[k] = (seg[k*2] + seg[k*2+1]) % mod;
	}
	void add(int a, int b, llint val){
		if(a > b) return;
		add(a, b, 1, 0, (1<<size)-1, val);
	}
 
	llint query(int a, int b, int k, int l, int r)
	{
		eval(l, r, k);
		
		if(b < l || r < a) return 0;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return (lval + rval) % mod;
	}
	llint query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, m;
llint l[200005], r[200005], p[200005];
llint L[200005], P[200005];
LazySegTree seg(18);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		cin >> l[i] >> r[i] >> p[i];
		L[r[i]] = l[i], P[r[i]] = p[i];
	}
	
	seg.init();
	seg.update(0, 1);
	
	for(int i = 1; i <= n; i++){
		if(L[i] == 0){
			seg.update(i, seg.query(0, i-1));
			seg.add(0, i-1, 2);
		}
		else{
			if(P[i] == 0){
				seg.update(i, seg.query(0, i-1));
				seg.add(0, L[i]-1, 0);
				seg.add(L[i], i-1, 2);
			}
			else seg.add(L[i], i-1, 0);
		}
		//for(int i = 0; i <= n; i++) cout << seg.query(i, i) << " "; cout << endl;
	}
	
	llint ans = seg.query(0, n);
	cout << ans << endl;
	
	return 0;
}
0