/*
* https://sio2.mimuw.edu.pl/c/pa-2020-1/p/kol/
*/
#include <iostream>
#include <vector>
#include <cassert>
#include <bitset>
using namespace std;
struct color {
int y = 0;
int b = 0;
int r = 0;
};
int main() {
int n, m;
std::cin >> n >> m;
vector<color> colors(n);
for (int i = 0 ; i < m; ++i) {
int l, r, k;
std::cin >> l >> r >> k;
if (k == 1) {
colors[l-1].y += 1;
colors[r].y -= 1;
} else if (k == 2) {
colors[l-1].b += 1;
colors[r].b -= 1;
} else if (k == 3) {
colors[l-1].r += 1;
colors[r].r -= 1;
} else {
assert(false);
}
}
int ctr = 0;
color current_color;
for (int i = 0 ; i < n; ++i) {
color c = colors[i];
current_color.y += c.y;
current_color.b += c.b;
current_color.r += c.r;
if (current_color.y > 0 && current_color.b > 0 && current_color.r == 0) {
ctr++;
}
}
std::cout << ctr << std::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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | /* * https://sio2.mimuw.edu.pl/c/pa-2020-1/p/kol/ */ #include <iostream> #include <vector> #include <cassert> #include <bitset> using namespace std; struct color { int y = 0; int b = 0; int r = 0; }; int main() { int n, m; std::cin >> n >> m; vector<color> colors(n); for (int i = 0 ; i < m; ++i) { int l, r, k; std::cin >> l >> r >> k; if (k == 1) { colors[l-1].y += 1; colors[r].y -= 1; } else if (k == 2) { colors[l-1].b += 1; colors[r].b -= 1; } else if (k == 3) { colors[l-1].r += 1; colors[r].r -= 1; } else { assert(false); } } int ctr = 0; color current_color; for (int i = 0 ; i < n; ++i) { color c = colors[i]; current_color.y += c.y; current_color.b += c.b; current_color.r += c.r; if (current_color.y > 0 && current_color.b > 0 && current_color.r == 0) { ctr++; } } std::cout << ctr << std::endl; } |
English