#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int INF = 1e9; const long long INFL = 1e18; const double PI = 3.14; const int mod = 1e9 + 7; typedef long long LL; typedef vector<int> vi; typedef list<int> li; typedef queue<int> qi; typedef pair<int,int> ii; typedef pair<LL, LL> ll; typedef map<string,int> msi; typedef set<int> sett; typedef vector<ii> vii; typedef priority_queue< ii, vector<ii>, greater<ii> > pq; vector<ii>::iterator iter; #define pb push_back #define pf push_front #define mp(x, y) make_pair(x, y) #define size(x) (int)x.size() #define endl '\n' int _X[] = {0, 1, 1, 1, 0, -1, -1, -1}; int _Y[] = {-1, -1, 0, 1, 1, 1, 0, -1}; int _X2[] = {1, 0, -1, 0}; int _Y2[] = {0, 1, 0, -1}; //FILE I/O void FILE_OI(){ fstream plik; plik.open("plik.txt"); //create plik.txt! plik << "_put here your input_"; plik.close(); } //DEBUG void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif ///////////////////////////////////////////////GLOBAL DEFINITIONS//////////////////////////////////////////////////////// LL n, q; LL leaf = (1 << 20); LL tree[3][3000005]; ///////////////////////////////////////////////////FUNCTIONS///////////////////////////////////////////////////////////// void update(LL l, LL r, LL k){ l += leaf; r += leaf; tree[k][l] += 1; if(l != r) tree[k][r] += 1; while(l / 2 != r / 2){ if(l % 2 == 0) tree[k][l+1] += 1; if(r % 2 == 1) tree[k][r-1] += 1; l /= 2; r /= 2; } } LL query_yellow(LL pos){ pos += leaf; LL ans = 0; while(pos){ ans += tree[0][pos]; pos /= 2; } return ans; } LL query_blue(LL pos){ pos += leaf; LL ans = 0; while(pos){ ans += tree[1][pos]; pos /= 2; } return ans; } LL query_red(LL pos){ pos += leaf; LL ans = 0; while(pos){ ans += tree[2][pos]; pos /= 2; } return ans; } /////////////////////////////////////////////////////MAIN//////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) {ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// cin >> n >> q; while(q--){ LL l, r, k; cin >> l >> r >> k; k--; update(l, r, k); } int res = 0; for(int i = 1; i <= n; i++){ bool check_yellow = false; bool check_blue = false; bool check_red = false; if(query_yellow(i) > 0) check_yellow = true; if(query_blue(i) > 0) check_blue = true; if(query_red(i) > 0) check_red = true; if(check_yellow == true && check_blue == true && check_red == false){ res++; } } cout << res << 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | #include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int INF = 1e9; const long long INFL = 1e18; const double PI = 3.14; const int mod = 1e9 + 7; typedef long long LL; typedef vector<int> vi; typedef list<int> li; typedef queue<int> qi; typedef pair<int,int> ii; typedef pair<LL, LL> ll; typedef map<string,int> msi; typedef set<int> sett; typedef vector<ii> vii; typedef priority_queue< ii, vector<ii>, greater<ii> > pq; vector<ii>::iterator iter; #define pb push_back #define pf push_front #define mp(x, y) make_pair(x, y) #define size(x) (int)x.size() #define endl '\n' int _X[] = {0, 1, 1, 1, 0, -1, -1, -1}; int _Y[] = {-1, -1, 0, 1, 1, 1, 0, -1}; int _X2[] = {1, 0, -1, 0}; int _Y2[] = {0, 1, 0, -1}; //FILE I/O void FILE_OI(){ fstream plik; plik.open("plik.txt"); //create plik.txt! plik << "_put here your input_"; plik.close(); } //DEBUG void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif ///////////////////////////////////////////////GLOBAL DEFINITIONS//////////////////////////////////////////////////////// LL n, q; LL leaf = (1 << 20); LL tree[3][3000005]; ///////////////////////////////////////////////////FUNCTIONS///////////////////////////////////////////////////////////// void update(LL l, LL r, LL k){ l += leaf; r += leaf; tree[k][l] += 1; if(l != r) tree[k][r] += 1; while(l / 2 != r / 2){ if(l % 2 == 0) tree[k][l+1] += 1; if(r % 2 == 1) tree[k][r-1] += 1; l /= 2; r /= 2; } } LL query_yellow(LL pos){ pos += leaf; LL ans = 0; while(pos){ ans += tree[0][pos]; pos /= 2; } return ans; } LL query_blue(LL pos){ pos += leaf; LL ans = 0; while(pos){ ans += tree[1][pos]; pos /= 2; } return ans; } LL query_red(LL pos){ pos += leaf; LL ans = 0; while(pos){ ans += tree[2][pos]; pos /= 2; } return ans; } /////////////////////////////////////////////////////MAIN//////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) {ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// cin >> n >> q; while(q--){ LL l, r, k; cin >> l >> r >> k; k--; update(l, r, k); } int res = 0; for(int i = 1; i <= n; i++){ bool check_yellow = false; bool check_blue = false; bool check_red = false; if(query_yellow(i) > 0) check_yellow = true; if(query_blue(i) > 0) check_blue = true; if(query_red(i) > 0) check_red = true; if(check_yellow == true && check_blue == true && check_red == false){ res++; } } cout << res << endl; return 0; } |