#include <iostream>
#include <map>
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define ZOLTY 0x0000001
#define NIEBIESKI 0x0000010
#define CZERWONY 0x0000100
#define ZIELONY 0x0000011
std::map<int, int> colors;
int main()
{
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
colors[1] = ZOLTY;
colors[2] = NIEBIESKI;
colors[3] = CZERWONY;
int m, n;
std::cin >> m >> n;
int* table = new int[m + 1];
FOR(i, m) {
table[i] = 0;
}
FOR(i, n) {
int x1, x2, color;
std::cin >> x1 >> x2 >> color;
for (int j = x1; j <= x2; j++) {
table[j] = table[j] | colors[color];
}
}
int value = 0;
FOR(i, n) {
if (table[i] == ZIELONY) value++;
}
std::cout << value << 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 | #include <iostream> #include <map> #define FOR(i, n) for(int i = 1; i<=n; i++) #define ZOLTY 0x0000001 #define NIEBIESKI 0x0000010 #define CZERWONY 0x0000100 #define ZIELONY 0x0000011 std::map<int, int> colors; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); colors[1] = ZOLTY; colors[2] = NIEBIESKI; colors[3] = CZERWONY; int m, n; std::cin >> m >> n; int* table = new int[m + 1]; FOR(i, m) { table[i] = 0; } FOR(i, n) { int x1, x2, color; std::cin >> x1 >> x2 >> color; for (int j = x1; j <= x2; j++) { table[j] = table[j] | colors[color]; } } int value = 0; FOR(i, n) { if (table[i] == ZIELONY) value++; } std::cout << value << std::endl; } |
English