#include <bits/stdc++.h>
using namespace std;
short op[3][1000006];
int main(){
int n,m;
ios_base::sync_with_stdio(0);
cin>>n>>m;
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
c--;b++;
op[c][a]++;
op[c][b]--;
}
int w=0;
int il[3]{};
for(int i=1;i<=n;i++){
for(int j=0;j<3;j++){
il[j]+=op[j][i];
}
if(il[0]>0&&il[1]>0&&il[2]==0){
w++;
}
}
cout<<w;
}
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 | #include <bits/stdc++.h> using namespace std; short op[3][1000006]; int main(){ int n,m; ios_base::sync_with_stdio(0); cin>>n>>m; for(int i=0;i<m;i++){ int a,b,c; cin>>a>>b>>c; c--;b++; op[c][a]++; op[c][b]--; } int w=0; int il[3]{}; for(int i=1;i<=n;i++){ for(int j=0;j<3;j++){ il[j]+=op[j][i]; } if(il[0]>0&&il[1]>0&&il[2]==0){ w++; } } cout<<w; } |
English