#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const pair&p){ os< ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,pair&p){ is>>p.first>>p.second; return is; } template istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } template struct ModInt{ long long x; ModInt():x(0){} ModInt(long long y):x(y>=0?y%Mod:(Mod-(-y)%Mod)%Mod){} ModInt &operator+=(const ModInt &p){ if((x+=p.x)>=Mod) x-=Mod; return *this; } ModInt &operator-=(const ModInt &p){ if((x+=Mod-p.x)>=Mod)x-=Mod; return *this; } ModInt &operator*=(const ModInt &p){ x=(int)(1ll*x*p.x%Mod); return *this; } ModInt &operator/=(const ModInt &p){ (*this)*=p.inverse(); return *this; } ModInt operator-()const{return ModInt(x);} ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;} ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;} ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;} ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;} ModInt operator==(const ModInt &p)const{return x==p.x;} ModInt operator!=(const ModInt &p)const{return x!=p.x;} ModInt inverse()const{ int a=x,b=Mod,u=1,v=0,t; while(b>0){ t=a/b; swap(a-=t*b,b);swap(u-=t*v,v); } return ModInt(u); } ModInt pow(long long n)const{ ModInt ret(1),mul(x); while(n>0){ if(n&1) ret*=mul; mul*=mul;n>>=1; } return ret; } friend ostream &operator<<(ostream &os,const ModInt &p){return os<>(istream &is,ModInt &a){long long t;is>>t;a=ModInt(t);return (is);} static int get_mod(){return Mod;} }; using mint=ModInt; template struct comcalc{ vector fact,finv,inv; comcalc():fact(MAX),finv(MAX),inv(MAX){ fact[0]=mint(1),fact[1]=mint(1),finv[0]=mint(1),finv[1]=mint(1),inv[1]=mint(1); for(int i=2;in-r) r=n-r; if(r==0) return 1; mint a=1,b=mint(fact_mod(r)).inverse(); for(int i=0;i; template struct LazySegmentTree{ using F=function; using G=function; using H=function; int sz,height; vector data; vector lazy; const F f; const G g; const H h; const Monoid M1; const OperatorMonoid OM0; LazySegmentTree(int n,const F f,const G g,const H h,const Monoid &M1,const OperatorMonoid OM0) : f(f),g(g),h(h),M1(M1),OM0(OM0) { sz=1;height=0; while(sz0;k--) data[k]=f(data[2*k+0],data[2*k+1]);} inline void propagate(int k){ if(lazy[k]!=OM0){ lazy[2*k+0]=h(lazy[2*k+0],lazy[k]); lazy[2*k+1]=h(lazy[2*k+1],lazy[k]); data[k]=reflect(k); lazy[k]=OM0; } } inline Monoid reflect(int k){ return lazy[k]==OM0?data[k]:g(data[k],lazy[k]); } inline void recalc(int k){ while(k>>=1)data[k]=f(reflect(2*k+0),reflect(2*k+1)); } inline void thrust(int k){ for(int i=height;i>0;i--) propagate(k>>i); } void update(int a,int b,const OperatorMonoid &x){ if(a>=b) return ; thrust(a+=sz);thrust(b+=sz-1); for(int l=a,r=b+1;l>=1,r>>=1){ if(l&1) lazy[l]=h(lazy[l],x),l++; if(r&1) --r,lazy[r]=h(lazy[r],x); } recalc(a);recalc(b); } Monoid query(int a,int b){ thrust(a+=sz);thrust(b+=sz-1); Monoid L=M1,R=M1; for(int l=a,r=b+1;l>=1,r>>=1){ if(l&1) L=f(L,reflect(l++)); if(r&1) R=f(reflect(--r),R); } return f(L,R); } Monoid operator[](const int &k){ return query(k,k+1); } }; // // range set range min // using M=ll; // using OM=ll; // const M M1=LINF; // const OM OM0=-LINF; // M segf(M a,M b){ // return (ab?a:b); // } // M segg(M a,OM b){ // return (b==OM0?a:b); // } // OM segh(OM a,OM b){ // return (b==OM0?a:b); // } // // range add range min // using M=ll; // using OM=ll; // const M M1=LINF; // const OM OM0=0; // M segf(M a,M b){ // return (ab?a:b); // } // M segg(M a,OM b){ // return a+b; // } // OM segh(OM a,OM b){ // return a+b; // } // range set range sum (sum, count) using M=pair; using OM=ll; const M M1=M(0,0); const OM OM0=-LINF; M segf(M a,M b){ return M(a.first+b.first,a.second+b.second); } M segg(M a,OM b){ return M(a.second*b,a.second); } ll segh(ll a,ll b){ return (b==OM0?a:b); } signed main(){ int n,m;cin>>n>>m; using P=pair; vector

b; vector a(n+1,-1); LazySegmentTree seg(n+1,segf,segg,segh,M1,OM0); auto query=[&](int l,int r){ return seg.query(l,r).first; }; seg.set(0,M(0,0)); for(int i=1;i<=n;i++)seg.set(i,M(0,1)); seg.build(); int k=0; rep(i,m){ int l,r,p;cin>>l>>r>>p; if(p==0){ a[r]=l; }else{ seg.update(l,r+1,1); k++; } } vector dp(n+1,0),sum(n+1,0); dp[0]=1; sum[0]=1; int lmx=0; for(int i=1;i<=n;i++){ if(query(i,i+1)==0){ if(lmx) dp[i]=sum[i-1]-mint(2).pow(i-lmx)*sum[lmx-1]; else dp[i]=sum[i-1]; } sum[i]=mint(2)*sum[i-1]+dp[i]; chmax(lmx,a[i]); } mint ans=0; for(int i=lmx;i<=n;i++){ ans+=dp[i]*mint(2).pow(n-i); } ans/=mint(2).pow(k); cout<