#include <iostream> using namespace std; int comp; long long st[2048576][3]; int tab[3]; bool zap(int x) // zapytanie { tab[0] = 0; tab[1] = 0; tab[2] = 0; x += comp; while (x) { for (int i = 0; i < 3; i++) { tab[i] += st[x][i]; } x >>= 1; } if ((tab[0] > 0 && tab[1] > 0) && tab[2] == 0) { return true; } else return false; } void ins(int a, int b, int c) { c--; a += comp; b += comp; while (a < b) { if (a & 1) { st[a][c] = 1; a >>= 1; ++a; } else { a >>= 1; } if (b & 1) { b >>= 1; } else { st[b][c] = 1; b >>= 1; --b; } } if (a == b) { st[a][c] = 1; } } int main() { int n, q, a, b, c; int ziel = 0; cin >> n >> q; comp = 1; while (comp < n) { comp <<= 1; } --comp; for (int i = 1; i <= q; ++i) { cin >> a >> b >> c; ins(a, b, c); } for (int i = 1; i <= n; i++) { if (zap(i) == true) { ziel++; } } cout << ziel; 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include <iostream> using namespace std; int comp; long long st[2048576][3]; int tab[3]; bool zap(int x) // zapytanie { tab[0] = 0; tab[1] = 0; tab[2] = 0; x += comp; while (x) { for (int i = 0; i < 3; i++) { tab[i] += st[x][i]; } x >>= 1; } if ((tab[0] > 0 && tab[1] > 0) && tab[2] == 0) { return true; } else return false; } void ins(int a, int b, int c) { c--; a += comp; b += comp; while (a < b) { if (a & 1) { st[a][c] = 1; a >>= 1; ++a; } else { a >>= 1; } if (b & 1) { b >>= 1; } else { st[b][c] = 1; b >>= 1; --b; } } if (a == b) { st[a][c] = 1; } } int main() { int n, q, a, b, c; int ziel = 0; cin >> n >> q; comp = 1; while (comp < n) { comp <<= 1; } --comp; for (int i = 1; i <= q; ++i) { cin >> a >> b >> c; ins(a, b, c); } for (int i = 1; i <= n; i++) { if (zap(i) == true) { ziel++; } } cout << ziel; return 0; } |