結果

問題 No.1222 -101
ユーザー milanis48663220milanis48663220
提出日時 2021-05-12 22:46:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 4,643 bytes
コンパイル時間 2,435 ms
コンパイル使用メモリ 124,016 KB
実行使用メモリ 8,936 KB
最終ジャッジ日時 2023-10-24 17:40:38
合計ジャッジ時間 7,063 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 85 ms
8,936 KB
testcase_11 AC 59 ms
8,936 KB
testcase_12 AC 88 ms
8,936 KB
testcase_13 AC 88 ms
8,936 KB
testcase_14 AC 88 ms
8,936 KB
testcase_15 AC 72 ms
8,936 KB
testcase_16 AC 79 ms
8,936 KB
testcase_17 AC 85 ms
8,936 KB
testcase_18 AC 74 ms
8,936 KB
testcase_19 AC 78 ms
8,936 KB
testcase_20 AC 80 ms
8,936 KB
testcase_21 AC 78 ms
8,936 KB
testcase_22 AC 2 ms
4,368 KB
testcase_23 AC 2 ms
4,368 KB
testcase_24 AC 2 ms
4,368 KB
testcase_25 AC 2 ms
4,368 KB
testcase_26 AC 2 ms
4,368 KB
testcase_27 AC 2 ms
4,368 KB
testcase_28 AC 2 ms
4,368 KB
testcase_29 AC 2 ms
4,368 KB
testcase_30 AC 2 ms
4,368 KB
testcase_31 AC 2 ms
4,368 KB
testcase_32 AC 119 ms
8,936 KB
testcase_33 AC 121 ms
8,936 KB
testcase_34 AC 58 ms
8,936 KB
testcase_35 AC 57 ms
8,936 KB
testcase_36 AC 57 ms
8,936 KB
testcase_37 AC 58 ms
8,936 KB
testcase_38 AC 56 ms
8,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0