#include <cstdio> #include <vector> struct CoverTree { #define nr (wp + wk + 1) >> 1 std::vector<unsigned> el; int s,p,k,color; CoverTree(int size) { s = (1<<(size+1)); el.resize(s); } void Add(int p1,int k1, int color1) { p = p1; k = k1; color = color1; Mark(0, s/2, 1); } unsigned Get(int p1) { unsigned result = 0; int g = (s/2) + p1; while (g>0) { result = result | el[g]; g /= 2; } return result; } private: void Mark(int wp, int wk, int g) { if (k<=wp || p>=wk) { return; } if (p<=wp && k>=wk) { el[g] = el[g] | (1U << color); } else { Mark(wp,nr,2*g); Mark(nr,wk,2*g+1); } } }; int main() { CoverTree ctree(20); int N,M; scanf("%d %d", &N, &M); for (int i=0; i<M; ++i) { int l,p,k; scanf("%d %d %d",&l,&p,&k); ctree.Add(l,p+1,k); } int result = 0; for (int i=1; i<=N; ++i) { if (ctree.Get(i) == 6) { result++; } } printf("%d\n", result); 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 | #include <cstdio> #include <vector> struct CoverTree { #define nr (wp + wk + 1) >> 1 std::vector<unsigned> el; int s,p,k,color; CoverTree(int size) { s = (1<<(size+1)); el.resize(s); } void Add(int p1,int k1, int color1) { p = p1; k = k1; color = color1; Mark(0, s/2, 1); } unsigned Get(int p1) { unsigned result = 0; int g = (s/2) + p1; while (g>0) { result = result | el[g]; g /= 2; } return result; } private: void Mark(int wp, int wk, int g) { if (k<=wp || p>=wk) { return; } if (p<=wp && k>=wk) { el[g] = el[g] | (1U << color); } else { Mark(wp,nr,2*g); Mark(nr,wk,2*g+1); } } }; int main() { CoverTree ctree(20); int N,M; scanf("%d %d", &N, &M); for (int i=0; i<M; ++i) { int l,p,k; scanf("%d %d %d",&l,&p,&k); ctree.Add(l,p+1,k); } int result = 0; for (int i=1; i<=N; ++i) { if (ctree.Get(i) == 6) { result++; } } printf("%d\n", result); return 0; } |