#include<bits/stdc++.h> using namespace std; using pii = pair<int, int>; using pll = pair<long long, long long>; using pil = pair<int, long long>; using pli = pair<long long, int>; using ll = long long; #define X first #define Y second #define pb push_back #define mp make_pair int n,m,k,l,r,t[2200007],rozm_t,wyn; void akt(int L, int R, int W){ if(L<=R && l<=L && R<=r){ if(k==1){ if(t[W]%2==0) t[W]++; } else if(k==2){ if(t[W]%4<2) t[W]=t[W]+2; } else{ if(t[W]<4) t[W]=t[W]+4; } return; } if(W>=rozm_t) return; int len = R-L+1; if(R-len/2>=l) akt(L,R-len/2,2*W); if(L+len/2<=r) akt(L+len/2,R,2*W+1); return; } void wynik(int W, bool K1, bool K2, bool K3){ if(K1 && t[W]%2==0) t[W]++; if(K2 && t[W]%4<2) t[W]=t[W]+2; if(K3 && t[W]<4) t[W]=t[W]+4; if(W>=rozm_t) { if(t[W]==3) wyn++; return; } bool k1=false,k2=false,k3=false; if(t[W]%2==1) k1=true; if(t[W]%4==2 || t[W]%4==3) k2=true; if(t[W]>3) k3=true; wynik(2*W,k1,k2,k3); wynik(2*W+1,k1,k2,k3); return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; rozm_t = 1; while(n>rozm_t-3) rozm_t=rozm_t*2; while(m--){ cin >> l >> r >> k; akt(1,rozm_t,1); } wynik(1,false,false,false); cout << wyn; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include<bits/stdc++.h> using namespace std; using pii = pair<int, int>; using pll = pair<long long, long long>; using pil = pair<int, long long>; using pli = pair<long long, int>; using ll = long long; #define X first #define Y second #define pb push_back #define mp make_pair int n,m,k,l,r,t[2200007],rozm_t,wyn; void akt(int L, int R, int W){ if(L<=R && l<=L && R<=r){ if(k==1){ if(t[W]%2==0) t[W]++; } else if(k==2){ if(t[W]%4<2) t[W]=t[W]+2; } else{ if(t[W]<4) t[W]=t[W]+4; } return; } if(W>=rozm_t) return; int len = R-L+1; if(R-len/2>=l) akt(L,R-len/2,2*W); if(L+len/2<=r) akt(L+len/2,R,2*W+1); return; } void wynik(int W, bool K1, bool K2, bool K3){ if(K1 && t[W]%2==0) t[W]++; if(K2 && t[W]%4<2) t[W]=t[W]+2; if(K3 && t[W]<4) t[W]=t[W]+4; if(W>=rozm_t) { if(t[W]==3) wyn++; return; } bool k1=false,k2=false,k3=false; if(t[W]%2==1) k1=true; if(t[W]%4==2 || t[W]%4==3) k2=true; if(t[W]>3) k3=true; wynik(2*W,k1,k2,k3); wynik(2*W+1,k1,k2,k3); return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; rozm_t = 1; while(n>rozm_t-3) rozm_t=rozm_t*2; while(m--){ cin >> l >> r >> k; akt(1,rozm_t,1); } wynik(1,false,false,false); cout << wyn; return 0; } |