#include <bits/stdc++.h> using namespace std; int baza = 1; short D[3000000]; void Z(int v, int p, int k, int pz, int kz, int w) { if(k < pz || p > kz) { return; } if(pz <= p && k <= kz) { D[v] |= w; return; } Z(2 * v, p, (p + k) / 2, pz, kz, w); Z((2 * v) + 1, ((p + k) / 2) + 1, k, pz, kz, w); return; } short w; short Q(int v) { v += baza; w = 0; while(v > 0) { w |= D[v]; v /= 2; } return w; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b; cin >> a >> b; while(baza < a) { baza *= 2; } int c, d, e; for(int i = 0; i < b; i++) { cin >> c >> d >> e; Z(1, 1, baza, c, d, (1 << (e - 1))); } int wyn = 0; for(int i = 0; i < a; i++) { wyn += (Q(i) == 3); } cout << wyn << 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 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 | #include <bits/stdc++.h> using namespace std; int baza = 1; short D[3000000]; void Z(int v, int p, int k, int pz, int kz, int w) { if(k < pz || p > kz) { return; } if(pz <= p && k <= kz) { D[v] |= w; return; } Z(2 * v, p, (p + k) / 2, pz, kz, w); Z((2 * v) + 1, ((p + k) / 2) + 1, k, pz, kz, w); return; } short w; short Q(int v) { v += baza; w = 0; while(v > 0) { w |= D[v]; v /= 2; } return w; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b; cin >> a >> b; while(baza < a) { baza *= 2; } int c, d, e; for(int i = 0; i < b; i++) { cin >> c >> d >> e; Z(1, 1, baza, c, d, (1 << (e - 1))); } int wyn = 0; for(int i = 0; i < a; i++) { wyn += (Q(i) == 3); } cout << wyn << endl; return 0; } |