#include <iostream> #include <vector> #include <tuple> using namespace std; /*int comb(int a, int b){ if(a > b){ swap(a,b); } if(a == 0){ return b; } else if(a == 1){ if(b == 1){ return 1; } else if(b == 2 || b==4){ return 4; } else if(b== 3 || b==5){ return 5; } else { return 7; } } else if(a==2){ if(b == 2){ return 2; } else if(b== 3 || b==6){ return 6; } else { return 7; } } else if(a==3) { if(b == 5 || b == 6){ return b; } } }*/ int main(){ int n, m; cin >> n >> m; vector<tuple<int,int,int>> Q(n, make_tuple(0, 0, 0)); while(m--){ int l, r, k; cin >> l >> r >> k; if(k-1 == 0){ get<0>(Q[l-1]) = 1; get<0>(Q[r-1]) = -1; } if(k-1 == 1){ get<1>(Q[l-1]) = 1; get<1>(Q[r-1]) = -1; } if(k-1 == 2){ get<2>(Q[l-1]) = 1; get<2>(Q[r-1]) = -1; } } int res = 0; tuple<int,int,int> temp = make_tuple(0,0,0); for(int i = 0; i < Q.size(); i++){ get<0>(temp) += get<0>(Q[i]); get<1>(temp) += get<1>(Q[i]); get<2>(temp) += get<2>(Q[i]); if(get<0>(temp) > 0 && get<1>(temp) > 0 && get<2>(temp) == 0){ res++; } } cout << res << 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 | #include <iostream> #include <vector> #include <tuple> using namespace std; /*int comb(int a, int b){ if(a > b){ swap(a,b); } if(a == 0){ return b; } else if(a == 1){ if(b == 1){ return 1; } else if(b == 2 || b==4){ return 4; } else if(b== 3 || b==5){ return 5; } else { return 7; } } else if(a==2){ if(b == 2){ return 2; } else if(b== 3 || b==6){ return 6; } else { return 7; } } else if(a==3) { if(b == 5 || b == 6){ return b; } } }*/ int main(){ int n, m; cin >> n >> m; vector<tuple<int,int,int>> Q(n, make_tuple(0, 0, 0)); while(m--){ int l, r, k; cin >> l >> r >> k; if(k-1 == 0){ get<0>(Q[l-1]) = 1; get<0>(Q[r-1]) = -1; } if(k-1 == 1){ get<1>(Q[l-1]) = 1; get<1>(Q[r-1]) = -1; } if(k-1 == 2){ get<2>(Q[l-1]) = 1; get<2>(Q[r-1]) = -1; } } int res = 0; tuple<int,int,int> temp = make_tuple(0,0,0); for(int i = 0; i < Q.size(); i++){ get<0>(temp) += get<0>(Q[i]); get<1>(temp) += get<1>(Q[i]); get<2>(temp) += get<2>(Q[i]); if(get<0>(temp) > 0 && get<1>(temp) > 0 && get<2>(temp) == 0){ res++; } } cout << res << endl; } |