#include <iostream> short colors[1 << 21] = {0}; unsigned int N = 1 << 20; void insert(int a, int b, int c){ int l = N + a; int r = N + b; colors[l] |= c; colors[r] |= c; while(l > 1){ if(l < r - 1){ if(l % 2 == 0){ colors[l + 1] |= c; } if(r % 2 == 1){ colors[r - 1] |= c; } } l /= 2; r /= 2; } } short query(int a){ short result = 0; int index = a + N; while(index > 0) { result |= colors[index]; index /= 2; } return result; } int main(){ int cans, operations; std::cin >> cans >> operations; for(int x=0; x<operations; x++){ int left, right, color; std::cin >> left >> right >> color; color--; left--; right--; insert(left, right, 1<<color); } int sum = 0; for(int x=0; x<cans; x++){ short q = query(x); if(q == 3){ sum++; } } std::cout << sum << std::endl; }
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 | #include <iostream> short colors[1 << 21] = {0}; unsigned int N = 1 << 20; void insert(int a, int b, int c){ int l = N + a; int r = N + b; colors[l] |= c; colors[r] |= c; while(l > 1){ if(l < r - 1){ if(l % 2 == 0){ colors[l + 1] |= c; } if(r % 2 == 1){ colors[r - 1] |= c; } } l /= 2; r /= 2; } } short query(int a){ short result = 0; int index = a + N; while(index > 0) { result |= colors[index]; index /= 2; } return result; } int main(){ int cans, operations; std::cin >> cans >> operations; for(int x=0; x<operations; x++){ int left, right, color; std::cin >> left >> right >> color; color--; left--; right--; insert(left, right, 1<<color); } int sum = 0; for(int x=0; x<cans; x++){ short q = query(x); if(q == 3){ sum++; } } std::cout << sum << std::endl; } |