結果
問題 | No.1222 -101 |
ユーザー |
![]() |
提出日時 | 2021-05-12 22:46:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 4,643 bytes |
コンパイル時間 | 1,188 ms |
コンパイル使用メモリ | 121,032 KB |
最終ジャッジ日時 | 2025-01-21 10:21:29 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include <iostream>#include <algorithm>#include <iomanip>#include <vector>#include <queue>#include <set>#include <map>#include <tuple>#include <cmath>#include <numeric>#include <functional>#include <cassert>#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }using namespace std;typedef long long ll;template<ll MOD>class ModInt{public:ll v;ModInt(ll _v = 0){if(_v >= MOD) _v %= MOD;v = _v;}ModInt operator+(ll n){return ModInt((v+n)%MOD);}ModInt operator-(ll n){return ModInt((v-n+MOD)%MOD);}ModInt operator*(ll n){if(n >= MOD) n %= MOD;return ModInt((v*n)%MOD);}ModInt operator/(ll n){return ModInt((ModInt(n).inv()*v).v%MOD);}void operator+=(ll n){v = (v+n)%MOD;}void operator-=(ll n){v = (v-n+MOD)%MOD;}void operator*=(ll n){v = (v*n+MOD)%MOD;}ModInt operator+(ModInt n){return ModInt((v+n.v)%MOD);}ModInt operator-(ModInt n){return ModInt((v-n.v+MOD)%MOD);}ModInt operator*(ModInt n){return ModInt((v*n.v)%MOD);}ModInt operator/(ModInt n){return ModInt((n.inv()*v).v%MOD);}void operator+=(ModInt n){v = (v+n.v)%MOD;}void operator-=(ModInt n){v = (v-n.v+MOD)%MOD;}void operator*=(ModInt n){v = (v*n.v)%MOD;}void operator=(ModInt n){v = n.v;}bool operator==(ModInt n){return v == n.v;}bool operator!=(ModInt n){return v != n.v;}void operator=(ll n){v = n%MOD;}ModInt inv(){if(v == 1) return ModInt(1);else return ModInt(MOD-ModInt(MOD%v).inv().v*(MOD/v)%MOD);}};template<ll MOD>ModInt<MOD> pow(ModInt<MOD> a, ll n) {assert(n >= 0);ModInt<MOD> ans = 1;ModInt<MOD> tmp = a;for (int i = 0; i <= 60; i++) {ll m = (ll)1 << i;if (m & n) {ans *= tmp;}tmp *= tmp;}return ans;}template<ll MOD>ostream& operator<<(ostream& os, const ModInt<MOD>& m){os << m.v;return os;}template<ll MOD>istream & operator >> (istream &in, ModInt<MOD> &m){in >> m.v;return in;}template <typename T>struct segtree{int n;T UNIT;vector<T> dat;T (*calc)(T, T);segtree(int n_, T unit, T (*_calc)(T, T)){UNIT = unit;calc = _calc;n = 1;while(n < n_) n *= 2;dat = vector<T>(2*n);for(int i = 0; i < 2*n; i++) dat[i] = UNIT;}void insert(int k, T a){dat[k+n-1] = a;}void update_all(){for(int i = n-2; i >= 0; i--){dat[i] = calc(dat[i*2+1], dat[i*2+2]);}}//k番目の値(0-indexed)をaに変更void update(int k, T a){k += n-1;dat[k] = a;while(k > 0){k = (k-1)/2;dat[k] = calc(dat[k*2+1], dat[k*2+2]);}}//[a, b)//区間[a, b]へのクエリに対してはquery(a, b+1)と呼ぶT query(int a, int b, int k=0, int l=0, int r=-1){if(r < 0) r = n;if(r <= a || b <= l) return UNIT;if(a <= l && r <= b) return dat[k];else{T vl = query(a, b, k*2+1, l, (l+r)/2);T vr = query(a, b, k*2+2, (l+r)/2, r);return calc(vl, vr);}}};using mint = ModInt<1000000007>;int main(){ios::sync_with_stdio(false);cin.tie(0);cout << setprecision(10) << fixed;int n, m; cin >> n >> m;vector<int> vl(n+1, -1);int cnt = 0;vector<int> imos(n+2);for(int i = 0; i < m; i++) {int l, r, p; cin >> l >> r >> p;if(p != 0){imos[l]++;imos[r+1]--;cnt++;}else vl[r] = l;}for(int i = 1; i <= n; i++) imos[i] += imos[i-1];segtree<mint> dp(n+1, mint(0), [](mint a, mint b){ return a+b; });dp.update(0, mint(1));mint inv2 = mint(2).inv();int l_max = 0;for(int r = 1; r <= n; r++){if(imos[r] == 0) {mint tmp = dp.query(l_max, r)*inv2;dp.update(r, tmp);}chmax(l_max, vl[r]);}cout << dp.query(l_max, n+1)*pow(mint(2), n-cnt) << endl;}