結果

問題 No.1222 -101
ユーザー firiexpfiriexp
提出日時 2020-09-04 23:07:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 698 ms / 2,000 ms
コード長 4,614 bytes
コンパイル時間 1,142 ms
コンパイル使用メモリ 111,544 KB
実行使用メモリ 11,188 KB
最終ジャッジ日時 2023-08-17 20:40:56
合計ジャッジ時間 10,774 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 301 ms
10,580 KB
testcase_11 AC 301 ms
10,604 KB
testcase_12 AC 465 ms
11,188 KB
testcase_13 AC 466 ms
10,716 KB
testcase_14 AC 468 ms
10,580 KB
testcase_15 AC 386 ms
10,576 KB
testcase_16 AC 424 ms
10,740 KB
testcase_17 AC 453 ms
10,656 KB
testcase_18 AC 388 ms
10,648 KB
testcase_19 AC 405 ms
11,188 KB
testcase_20 AC 440 ms
10,652 KB
testcase_21 AC 432 ms
10,652 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 696 ms
10,744 KB
testcase_33 AC 698 ms
10,584 KB
testcase_34 AC 355 ms
10,584 KB
testcase_35 AC 362 ms
10,648 KB
testcase_36 AC 251 ms
10,600 KB
testcase_37 AC 260 ms
10,720 KB
testcase_38 AC 256 ms
10,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class M>
struct LazySegmentTree{
    using T = typename M::T;
    using L = typename M::L;
    int sz, height{};
    vector<T> seg; vector<L> lazy;
    explicit LazySegmentTree(int n) {
        sz = 1; while(sz < n) sz <<= 1, height++;
        seg.assign(2*sz, M::e());
        lazy.assign(2*sz, M::l());
    }

    void set(int k, const T &x){
        seg[k + sz] = x;
    }

    void build(){
        for (int i = sz-1; i > 0; --i) seg[i] = M::f(seg[i<<1], seg[(i<<1)|1]);
    }

    T reflect(int k){ return lazy[k] == M::l() ? seg[k] : M::g(seg[k], lazy[k]); }

    void eval(int k){
        if(lazy[k] == M::l()) return;
        lazy[(k<<1)|0] = M::h(lazy[(k<<1)|0], lazy[k]);
        lazy[(k<<1)|1] = M::h(lazy[(k<<1)|1], lazy[k]);
        seg[k] = reflect(k);
        lazy[k] = M::l();
    }
    void thrust(int k){ for (int i = height; i; --i) eval(k>>i); }
    void recalc(int k) { while(k >>= 1) seg[k] = M::f(reflect((k<<1)|0), reflect((k<<1)|1));}
    void update(int a, int b, const L &x){
        thrust(a += sz); thrust(b += sz-1);
        for (int l = a, r = b+1;l < r; l >>=1, r >>= 1) {
            if(l&1) lazy[l] = M::h(lazy[l], x), l++;
            if(r&1) --r, lazy[r] = M::h(lazy[r], x);
        }
        recalc(a);
        recalc(b);
    }

    T query(int a, int b){ // [l, r)
        thrust(a += sz);
        thrust(b += sz-1);
        T ll = M::e(), rr = M::e();
        for(int l = a, r = b+1; l < r; l >>=1, r>>=1) {
            if (l & 1) ll = M::f(ll, reflect(l++));
            if (r & 1) rr = M::f(reflect(--r), rr);
        }
        return M::f(ll, rr);
    }
};

template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;
struct Monoid{
    using T = mint;
    using L = pair<mint, mint>;
    static T f(T a, T b) { return a + b; }
    static T g(T a, L b) {
        return a * b.first + b.second;
    }
    static L h(L a, L b) {
        return {a.first*b.first, a.second*b.first+b.second};
    }
    static T e() { return {0}; }
    static L l() { return {1, 0}; }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> ls(n+1, -1), ps(n+1, -1);
    LazySegmentTree<Monoid> dp(n+1);
    for (int i = 0; i < m; ++i) {
        int l, r, p;
        cin >> l >> r >> p;
        ls[r] = l;
        ps[r] = p;
    }
    dp.update(0, 1, {0, 1});
    for (int i = 1; i <= n; ++i) {
        if(ls[i] != -1){
            if(ps[i]){
                dp.update(ls[i], n+1, {0, 0});
            }else {
                mint x = dp.query(0, i);
                dp.update(0, ls[i], {0, 0});
                dp.update(ls[i], i, {2, 0});
                dp.update(i, i+1, {0, x});
            }
        }else {
            mint x = dp.query(0, i);
            dp.update(0, i, {2, 0});
            dp.update(i, i+1, {0, x});
        }
        /*for (int j = 0; j <= n; ++j) {
            printf("%d ", dp.query(j, j+1).val);
        }
          puts("");*/
       
    }
    cout << dp.query(0, n+1).val << "\n";
    return 0;
}
0