#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+6;
int kol[4][maxn];
int main(){
int n,m;
scanf("%d %d", &n, &m);
int l,r,k;
while(m--){
scanf("%d %d %d", &l, &r, &k);
kol[k][l]++;
kol[k][r+1]--;
}
for(int i=1; i<=3; i++){
int cnt = 0;
for(int p = 1; p<=n; p++){
cnt += kol[i][p];
kol[i][p] = cnt;
}
}
int ile = 0;
for(int p = 1; p<=n; p++){
if((kol[1][p]>0) && (kol[2][p] > 0) && (kol[3][p]==0)){
ile++;
}
}
cout<<ile<<endl;
}
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 | #include <bits/stdc++.h> using namespace std; const int maxn=1e6+6; int kol[4][maxn]; int main(){ int n,m; scanf("%d %d", &n, &m); int l,r,k; while(m--){ scanf("%d %d %d", &l, &r, &k); kol[k][l]++; kol[k][r+1]--; } for(int i=1; i<=3; i++){ int cnt = 0; for(int p = 1; p<=n; p++){ cnt += kol[i][p]; kol[i][p] = cnt; } } int ile = 0; for(int p = 1; p<=n; p++){ if((kol[1][p]>0) && (kol[2][p] > 0) && (kol[3][p]==0)){ ile++; } } cout<<ile<<endl; } |
English