#include <bits/stdc++.h> using namespace std; int main(){ // ios::sync_with_stdio(false); /// cin.tie(NULL) ; //int Z; cin >>Z; while(Z>0){Z--; int n, m; cin >> n; cin >> m; int l = 1; while(l <= n) l *= 2; l*=2; vector<vector<bool>> tree(2*l, vector<bool>(3)); /* auto query = [&](int v){ v+=l; int sum = 0; while(v){ sum+= tree[v]; v/=2; } return sum; };*/ auto update = [&](int p, int q, int x){ p+=l; q+=l; //int res = tree[p]; tree[p][x] = true; while(p/2 != q/2){ if(p%2 == 0) tree[p+1][x] = true; if(q%2 == 1) tree[q-1][x] = true; p/=2; q/=2; } }; for(int i = 0; i < m; i ++){ int k1, k2,k3; cin >> k1; cin >> k2; cin >> k3; // cout << "a"; update(k1-1, k2-1+1, k3-1); // cout << "b"; } // cout << "s"; for(int x = 2; x < 2*l; x ++){ for(int y = 0; y < 3; y ++){ tree[x][y] = tree[x][y] or tree[x/2][y]; } } int sum = 0; // cout << "w"; for(int x = l+0; x < l+n; x ++){ if(tree[x][0] and tree[x][1] and !tree[x][2]) sum++; } cout << sum << 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 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 | #include <bits/stdc++.h> using namespace std; int main(){ // ios::sync_with_stdio(false); /// cin.tie(NULL) ; //int Z; cin >>Z; while(Z>0){Z--; int n, m; cin >> n; cin >> m; int l = 1; while(l <= n) l *= 2; l*=2; vector<vector<bool>> tree(2*l, vector<bool>(3)); /* auto query = [&](int v){ v+=l; int sum = 0; while(v){ sum+= tree[v]; v/=2; } return sum; };*/ auto update = [&](int p, int q, int x){ p+=l; q+=l; //int res = tree[p]; tree[p][x] = true; while(p/2 != q/2){ if(p%2 == 0) tree[p+1][x] = true; if(q%2 == 1) tree[q-1][x] = true; p/=2; q/=2; } }; for(int i = 0; i < m; i ++){ int k1, k2,k3; cin >> k1; cin >> k2; cin >> k3; // cout << "a"; update(k1-1, k2-1+1, k3-1); // cout << "b"; } // cout << "s"; for(int x = 2; x < 2*l; x ++){ for(int y = 0; y < 3; y ++){ tree[x][y] = tree[x][y] or tree[x/2][y]; } } int sum = 0; // cout << "w"; for(int x = l+0; x < l+n; x ++){ if(tree[x][0] and tree[x][1] and !tree[x][2]) sum++; } cout << sum << endl; }//} |