#include<bits/stdc++.h>
#define FOR(i,be,en) for(int i=be; i<en; i++)
using namespace std;
const int MAXN=1e6+5, B=(1<<20), G=3;
int T[(B<<1)];
void Change(int l, int r, int c){
l+=B;
r+=B;
int M=(1<<c);
while(l<r){
if((l&1)){
T[l]|=M;
l++;
}
if(!(r&1)){
T[r]|=M;
r--;
}
l>>=1;
r>>=1;
}
if(l==r) T[l]|=M;
}
int Ask(int pos){
pos+=B;
int res=0;
while(pos){
res|=T[pos];
pos>>=1;
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
FOR(i,0,m){
int l,r,k;
cin>>l>>r>>k;
Change(l,r,k-1);
}
int ans=0;
FOR(i,1,n+1){
if(Ask(i)==G) ans++;
}
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 60 61 | #include<bits/stdc++.h> #define FOR(i,be,en) for(int i=be; i<en; i++) using namespace std; const int MAXN=1e6+5, B=(1<<20), G=3; int T[(B<<1)]; void Change(int l, int r, int c){ l+=B; r+=B; int M=(1<<c); while(l<r){ if((l&1)){ T[l]|=M; l++; } if(!(r&1)){ T[r]|=M; r--; } l>>=1; r>>=1; } if(l==r) T[l]|=M; } int Ask(int pos){ pos+=B; int res=0; while(pos){ res|=T[pos]; pos>>=1; } return res; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,m; cin>>n>>m; FOR(i,0,m){ int l,r,k; cin>>l>>r>>k; Change(l,r,k-1); } int ans=0; FOR(i,1,n+1){ if(Ask(i)==G) ans++; } cout<<ans; return 0; } |
English