#include #include #include #include #include #include #include #include #include #include #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 void chmin(T &a,const T &b){if(a>b) a=b;} template void chmax(T &a,const T &b){if(a template< typename T, typename S > struct LazySegmentTree{ int n; vector data; vector 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 &A){ for(int k=0;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 seg(N,te,se); vector init(N,0); seg.build(init); */ int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,M; cin>>N>>M; vector L(M),R(M),P(M); rep(i,M) cin>>L[i]>>R[i]>>P[i]; vector qry(N+1,-1); rep(i,M){ qry[R[i]]=i; } ll te=0,se=0; LazySegmentTree seg(N+1,0,1); vector 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<