#include <iostream>
using namespace std;
struct Colors {
int yellow = 0;
int blue = 0;
int red = 0;
};
Colors baskets[1'000'010];
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for(int i = 0; i < m; ++i) {
int a, b, c;
cin >> a >> b >> c;
if(c == 1) {
baskets[a].yellow += 1;
baskets[b+1].yellow -= 1;
} else if(c == 2) {
baskets[a].blue += 1;
baskets[b+1].blue -= 1;
} else {
baskets[a].red += 1;
baskets[b+1].red -= 1;
}
}
int x = 0, y = 0, z = 0, res = 0;
for(int i = 1; i <= n; ++i) {
x += baskets[i].yellow;
y += baskets[i].blue;
z += baskets[i].red;
if(x > 0 && y > 0 && z == 0) {
++res;
}
}
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <iostream> using namespace std; struct Colors { int yellow = 0; int blue = 0; int red = 0; }; Colors baskets[1'000'010]; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for(int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c; if(c == 1) { baskets[a].yellow += 1; baskets[b+1].yellow -= 1; } else if(c == 2) { baskets[a].blue += 1; baskets[b+1].blue -= 1; } else { baskets[a].red += 1; baskets[b+1].red -= 1; } } int x = 0, y = 0, z = 0, res = 0; for(int i = 1; i <= n; ++i) { x += baskets[i].yellow; y += baskets[i].blue; z += baskets[i].red; if(x > 0 && y > 0 && z == 0) { ++res; } } cout << res << endl; return 0; } |
English