結果

問題 No.1222 -101
ユーザー snow39snow39
提出日時 2020-09-05 01:02:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 368 ms / 2,000 ms
コード長 3,811 bytes
コンパイル時間 1,050 ms
コンパイル使用メモリ 104,464 KB
実行使用メモリ 16,176 KB
最終ジャッジ日時 2024-05-05 03:59:13
合計ジャッジ時間 6,914 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 240 ms
13,824 KB
testcase_11 AC 158 ms
13,748 KB
testcase_12 AC 246 ms
16,092 KB
testcase_13 AC 247 ms
16,120 KB
testcase_14 AC 249 ms
16,072 KB
testcase_15 AC 205 ms
15,104 KB
testcase_16 AC 229 ms
15,548 KB
testcase_17 AC 246 ms
16,000 KB
testcase_18 AC 210 ms
14,988 KB
testcase_19 AC 230 ms
15,300 KB
testcase_20 AC 235 ms
15,636 KB
testcase_21 AC 227 ms
15,660 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 368 ms
16,072 KB
testcase_33 AC 362 ms
16,128 KB
testcase_34 AC 227 ms
16,128 KB
testcase_35 AC 230 ms
16,128 KB
testcase_36 AC 164 ms
16,084 KB
testcase_37 AC 164 ms
16,176 KB
testcase_38 AC 164 ms
16,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}


#include <functional>

template< typename T, typename S >
struct LazySegmentTree{
    int n;
    vector<T> data;
    vector<S> lazy;
    T te;
    S se;

    inline void merge_functions(S& lazy,S& val){
        //lazy+=val;
        //lazy=val;
        //lazy=lazy*val%MOD;
        //ll coef=0;
        //if(val) mod_pow(2,val);
        lazy=(lazy*val)%MOD;
    }
    inline void operate(T& data,S& val,int len){
        //data+=val*len;
        //data=val*len;
        //data=data*val%MOD;
        //data+=val;
        //data=val;

        val%=MOD;
        data=data*val%MOD;
    }
    inline T merge_values(T& x,T& y){
        return (x+y)%MOD;
        //return min(x,y);
        //return max(x,y);
    }

    LazySegmentTree(){}
    LazySegmentTree(int sz,T te,S se):te(te),se(se){
        n=1;
        while(n<sz) n*=2;
        data.resize(2*n-1,te);
        lazy.resize(2*n-1,se);
    }

    void build(vector<T> &A){
        for(int k=0;k<int(A.size());k++) data[k+n-1]=A[k];
        for(int k=n-2;k>=0;k--) data[k]=merge_values(data[2*k+1],data[2*k+2]);
    }

    void eval(int k,int l,int r){
        if(lazy[k]==se) return;
        operate(data[k],lazy[k],r-l);
        if(r-l>1){
            merge_functions(lazy[2*k+1],lazy[k]);
            merge_functions(lazy[2*k+2],lazy[k]);
        }
        lazy[k]=se;
    }

    void update(int a,int b,S val,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l||r<=a) return;
        if(a<=l&&r<=b){
            merge_functions(lazy[k],val);
            eval(k,l,r);
        }else{
            update(a,b,val,2*k+1,l,(l+r)/2);
            update(a,b,val,2*k+2,(l+r)/2,r);
            data[k]=merge_values(data[2*k+1],data[2*k+2]);
        }
    }

    T query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l||r<=a) return te;
        if(a<=l&&r<=b) return data[k];

        T vl=query(a,b,2*k+1,l,(l+r)/2);
        T vr=query(a,b,2*k+2,(l+r)/2,r);
        return merge_values(vl,vr);
    }
};

/*
  LazySegmentTree<ll,ll> seg(N,te,se);
  vector<ll> init(N,0);
  seg.build(init);
*/

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N,M;
  cin>>N>>M;
  vector<int> L(M),R(M),P(M);
  rep(i,M) cin>>L[i]>>R[i]>>P[i];

  vector<int> qry(N+1,-1);
  rep(i,M){
      qry[R[i]]=i;
  }

  ll te=0,se=0;
  LazySegmentTree<ll,ll> seg(N+1,0,1);
  vector<ll> init(N+1,1);
  seg.build(init);

  int edge=0;
  for(int i=1;i<=N;i++){
      if(qry[i]==-1){
          auto val=seg.query(edge,i);
          seg.update(i,i+1,val);// 0
          seg.update(edge,i,2);// 1 or -1

          continue;
      }

      int now=qry[i];
      int lef=L[now];
      if(P[now]==0){
          auto val=seg.query(edge,i);
          seg.update(i,i+1,val);// 0
          seg.update(lef,i,2);// 1 or -1

          chmax(edge,lef);
      }else if(P[now]==1){
          if(lef<=edge){
              cout<<0<<endl;
              return 0;
          }
          seg.update(lef,i+1,0);// 0
          //seg.update(edge,lef,2);// 1 or -1
      }else{
          if(lef<=edge){
              cout<<0<<endl;
              return 0;
          }
          seg.update(lef,i+1,0);// 0
          //seg.update(edge,lef,2);// 1 or -1
      }
  }

  auto val=seg.query(edge,N+1);
  ll ans=val;
  cout<<ans<<endl;

  return 0;
}
0