#include <bits/stdc++.h> int tab[2097152]; int getGreen(int v, int lef, int rig, int pos) { if (lef == rig) return tab[v]; int mid = (lef + rig) / 2; if (pos <= mid) return tab[v] | getGreen(v*2, lef, mid, pos); else return tab[v] | getGreen(v*2+1, mid+1, rig, pos); } void update(int v, int lef, int rig, int l, int r, int add) { if (l > r) return; if (l == lef && r == rig) { tab[v] = tab[v] | add; //printf("doorowalem %i i dostalem tab[v] = %i, oraz v = %i\n", add, tab[v], v); } else { int mid = (lef + rig) / 2; update(v*2, lef, mid, l, std::min(r, mid), add); update(v*2+1, mid+1, rig, std::max(l, mid+1), r, add); } } int main(){ int n, m; scanf("%i%i", &n, &m); for (int i=0; i<m; i++){ int a,b,c; scanf("%i%i%i", &a, &b, &c); if (c==3){ c++; } a--; b--; update(1, 0, n-1, a, b, c); } int wynik = 0; for (int i=0; i<n; i++){ if (getGreen(1, 0, n-1, i)==3){ wynik++; } } printf("%i", wynik); }
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 | #include <bits/stdc++.h> int tab[2097152]; int getGreen(int v, int lef, int rig, int pos) { if (lef == rig) return tab[v]; int mid = (lef + rig) / 2; if (pos <= mid) return tab[v] | getGreen(v*2, lef, mid, pos); else return tab[v] | getGreen(v*2+1, mid+1, rig, pos); } void update(int v, int lef, int rig, int l, int r, int add) { if (l > r) return; if (l == lef && r == rig) { tab[v] = tab[v] | add; //printf("doorowalem %i i dostalem tab[v] = %i, oraz v = %i\n", add, tab[v], v); } else { int mid = (lef + rig) / 2; update(v*2, lef, mid, l, std::min(r, mid), add); update(v*2+1, mid+1, rig, std::max(l, mid+1), r, add); } } int main(){ int n, m; scanf("%i%i", &n, &m); for (int i=0; i<m; i++){ int a,b,c; scanf("%i%i%i", &a, &b, &c); if (c==3){ c++; } a--; b--; update(1, 0, n-1, a, b, c); } int wynik = 0; for (int i=0; i<n; i++){ if (getGreen(1, 0, n-1, i)==3){ wynik++; } } printf("%i", wynik); } |