#include <iostream>
#include <cstring>
using namespace std;
int main() {
int n, m, res;
cin >> n >> m;
int kolory[3][n+1];
memset(kolory, 0, 3*(n+1)*(sizeof(int)));
int aktualne[] = {0 , 0, 0};
for (int i = 0; i < m; i++) {
int l, r, c;
cin >> l >> r >> c;
kolory[c-1][l-1]++;
kolory[c-1][r]--;
}
res = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) aktualne[j]+=kolory[j][i];
res += (aktualne[0] && aktualne[1] && !aktualne[2]);
}
cout << res << endl;
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 | #include <iostream> #include <cstring> using namespace std; int main() { int n, m, res; cin >> n >> m; int kolory[3][n+1]; memset(kolory, 0, 3*(n+1)*(sizeof(int))); int aktualne[] = {0 , 0, 0}; for (int i = 0; i < m; i++) { int l, r, c; cin >> l >> r >> c; kolory[c-1][l-1]++; kolory[c-1][r]--; } res = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) aktualne[j]+=kolory[j][i]; res += (aktualne[0] && aktualne[1] && !aktualne[2]); } cout << res << endl; return 0; } |
English