#include #include #include #include #include using namespace std; typedef long long ll; int par[400010],sz[400010]; void init(int n){ for(int i=0;isz[y]) swap(x,y); par[x] = y; sz[y] += sz[x]; } bool same(int x, int y){ return find(x)==find(y); } ll mod = 1000000007; ll pw(ll a, ll x){ ll ret = 1; while(x){ if(x&1) (ret *= a) %= mod; (a *= a) %= mod; x /= 2; } return ret; } int cnt[200010] = {},ind[200010] = {}; vector z,nz; vector,int>> v[2]; map mp; ll dp[200010],sum[200010]; int main(){ int i,n,m; cin >> n >> m; for(i=0;i> l >> r >> p; if(p==0) v[0].push_back({{l,r},0}); else{ v[1].push_back({{l,r},p}); cnt[l]++; cnt[r + 1]--; } } for(i=0;ir){ cout << 0 << endl; return 0; } l = k; r = z[upper_bound(z.begin(),z.end(),r) - z.begin() - 1]; p = {{r,l},0}; } sort(v[0].begin(),v[0].end()); for(auto p:v[0]) ind[p.first.first + 1] = max(ind[p.first.first + 1],p.first.second); for(i=1;i<=n + 1;i++) ind[i] = max(ind[i],ind[i - 1]); ll inv = (mod + 1)/2; dp[0] = 1; sum[0] = 0; mp[0] = 0; for(i=1;i=x) (ans += dp[i]*pw(2,z.size() - 2)%mod) %= mod; } init(2*n + 1); for(auto p:v[1]){ int l = p.first.first - 1,r = p.first.second; l = nz[upper_bound(nz.begin(),nz.end(),l) - nz.begin() - 1]; if(p.second==1){ if(l>1) unite(2*l - 1,2*r - 1),unite(2*l,2*r); else unite(0,2*r - 1); } if(p.second==-1){ if(l>1) unite(2*l - 1,2*r),unite(2*l,2*r - 1); else unite(0,2*r); } } ll ans1 = 1; for(int x:nz){ if(x==0 || find(2*x - 1)!=2*x - 1) continue; if(same(2*x - 1,2*x)){ cout << 0 << endl; return 0; } if(same(0,2*x - 1) || same(0,2*x)) continue; (ans1 *= 2) %= mod; } cout << ans*ans1%mod << endl; }