//#include "testarka.cpp" #include <bits/stdc++.h> using namespace std; #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define ll long long int mod=1000000007; int inf=1000000007; ll infl=1000000000000000007; int seg[4000007],pot=1; void ins(int v,int a,int b,int l,int r,int c) { if(a<=l&&b>=r) { seg[v]|=(1<<c); return; } if(r<a||l>b) return; ins(2*v,a,b,l,(l+r)/2,c); ins(2*v+1,a,b,(l+r)/2+1,r,c); } int que(int v) { int an=0,y=v+pot-1; while(y>0) { an|=seg[y]; y/=2; } if(an==6) return 1; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,l,r,c,ans=0; cin>>n>>m; pot=1; while(pot<n) pot*=2; while(m--) { cin>>l>>r>>c; ins(1,l,r,1,pot,c); } for(int i=1;i<=n;i++) ans+=que(i); //for(int i=0;i<=2*pot;i++) seg[i]=0; cout<<ans; 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 | //#include "testarka.cpp" #include <bits/stdc++.h> using namespace std; #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define ll long long int mod=1000000007; int inf=1000000007; ll infl=1000000000000000007; int seg[4000007],pot=1; void ins(int v,int a,int b,int l,int r,int c) { if(a<=l&&b>=r) { seg[v]|=(1<<c); return; } if(r<a||l>b) return; ins(2*v,a,b,l,(l+r)/2,c); ins(2*v+1,a,b,(l+r)/2+1,r,c); } int que(int v) { int an=0,y=v+pot-1; while(y>0) { an|=seg[y]; y/=2; } if(an==6) return 1; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,l,r,c,ans=0; cin>>n>>m; pot=1; while(pot<n) pot*=2; while(m--) { cin>>l>>r>>c; ins(1,l,r,1,pot,c); } for(int i=1;i<=n;i++) ans+=que(i); //for(int i=0;i<=2*pot;i++) seg[i]=0; cout<<ans; return 0; } |