#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
auto *kolorPuszki = new short[n];
for (int i = 0; i < n; ++i) {
kolorPuszki[i] = 0;
}
int l, r, k, wynik = 0;
for (int i = 0; i < m; ++i) {
cin >> l >> r >> k;
for (int j = l; j <= r; ++j) {
if (kolorPuszki[j] == 0) {
if (k == 1 || k == 2) kolorPuszki[j] = k;
else kolorPuszki[j] = -1;
} else if (kolorPuszki[j] == 1) {
if (k == 1) kolorPuszki[j] = k;
else if (k == 2) {
kolorPuszki[j] = 4;
wynik++;
} else if (k == 3) kolorPuszki[j] = -1;
} else if (kolorPuszki[j] == 2) {
if (k == 1) {
kolorPuszki[j] = 4;
wynik++;
} else if (k == 2) kolorPuszki[j] = 2;
else if (k == 3) kolorPuszki[j] = -1;
} else if (kolorPuszki[j] == 4) {
if (k == 3) {
kolorPuszki[j] = -1;
wynik--;
}
}
}
}
cout << wynik;
delete[] kolorPuszki;
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 44 45 46 47 | #include <iostream> using namespace std; int main() { int n, m; cin >> n >> m; auto *kolorPuszki = new short[n]; for (int i = 0; i < n; ++i) { kolorPuszki[i] = 0; } int l, r, k, wynik = 0; for (int i = 0; i < m; ++i) { cin >> l >> r >> k; for (int j = l; j <= r; ++j) { if (kolorPuszki[j] == 0) { if (k == 1 || k == 2) kolorPuszki[j] = k; else kolorPuszki[j] = -1; } else if (kolorPuszki[j] == 1) { if (k == 1) kolorPuszki[j] = k; else if (k == 2) { kolorPuszki[j] = 4; wynik++; } else if (k == 3) kolorPuszki[j] = -1; } else if (kolorPuszki[j] == 2) { if (k == 1) { kolorPuszki[j] = 4; wynik++; } else if (k == 2) kolorPuszki[j] = 2; else if (k == 3) kolorPuszki[j] = -1; } else if (kolorPuszki[j] == 4) { if (k == 3) { kolorPuszki[j] = -1; wynik--; } } } } cout << wynik; delete[] kolorPuszki; return 0; } |
English