#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
int n,m;
vector<pair<int,int> > act[3];
int colour[1123456];
void paint(int mask,vector<pair<int,int> > &vec){
sort(vec.begin(),vec.end());
vec.push_back({inf,inf});
int which=0;
int range=0;
for(int now=1;now<=n;now++){
while(now==vec[which].first){
range=max(range,vec[which].second);
which++;
}
if(now <= range){
colour[now]+=mask;
}
}
}
int main(){
cin >>n >>m;
for(int i=0;i<m;i++){
int l,r,k;
cin >>l >>r >>k;
act[k-1].push_back({l,r});
}
paint(1,act[0]);
paint(2,act[1]);
paint(4,act[2]);
int ans=0;
for(int i=1;i<=n;i++){
ans+=colour[i]==0b011;
}
cout <<ans;
}
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 | #include<bits/stdc++.h> using namespace std; const int inf=1e9; int n,m; vector<pair<int,int> > act[3]; int colour[1123456]; void paint(int mask,vector<pair<int,int> > &vec){ sort(vec.begin(),vec.end()); vec.push_back({inf,inf}); int which=0; int range=0; for(int now=1;now<=n;now++){ while(now==vec[which].first){ range=max(range,vec[which].second); which++; } if(now <= range){ colour[now]+=mask; } } } int main(){ cin >>n >>m; for(int i=0;i<m;i++){ int l,r,k; cin >>l >>r >>k; act[k-1].push_back({l,r}); } paint(1,act[0]); paint(2,act[1]); paint(4,act[2]); int ans=0; for(int i=1;i<=n;i++){ ans+=colour[i]==0b011; } cout <<ans; } |
English