#include<bits/stdc++.h> using namespace std; vector<bool>oneIs; vector<bool>secondIs; vector<bool>thirdIs; vector<int>oneNext; vector<int>secondNext; vector<int>thirdNext; int main() { int n, m, j, nextJ, from, to, which, result = 0; cin >> n >> m; for(int i = 0; i < n; i++) { oneIs.push_back(false); secondIs.push_back(false); thirdIs.push_back(false); oneNext.push_back(i+1); secondNext.push_back(i+1); thirdNext.push_back(i+1); } for(int i = 0; i < m; i++) { cin >> from >> to >> which; from -= 1; to -= 1; j = from; while(j <= to) { if(which == 1) { oneIs[j] = true; nextJ = oneNext[j]; oneNext[j] = max(oneNext[j], to+1); j = nextJ; } else if(which == 2) { secondIs[j] = true; nextJ = secondNext[j]; secondNext[j] = max(secondNext[j], to+1); j = nextJ; } else { thirdIs[j] = true; nextJ = thirdNext[j]; thirdNext[j] = max(thirdNext[j], to+1); j = nextJ; } } } for(int i = 0; i < n; i++) if(oneIs[i] && secondIs[i] && !thirdIs[i]) result++; cout << 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 | #include<bits/stdc++.h> using namespace std; vector<bool>oneIs; vector<bool>secondIs; vector<bool>thirdIs; vector<int>oneNext; vector<int>secondNext; vector<int>thirdNext; int main() { int n, m, j, nextJ, from, to, which, result = 0; cin >> n >> m; for(int i = 0; i < n; i++) { oneIs.push_back(false); secondIs.push_back(false); thirdIs.push_back(false); oneNext.push_back(i+1); secondNext.push_back(i+1); thirdNext.push_back(i+1); } for(int i = 0; i < m; i++) { cin >> from >> to >> which; from -= 1; to -= 1; j = from; while(j <= to) { if(which == 1) { oneIs[j] = true; nextJ = oneNext[j]; oneNext[j] = max(oneNext[j], to+1); j = nextJ; } else if(which == 2) { secondIs[j] = true; nextJ = secondNext[j]; secondNext[j] = max(secondNext[j], to+1); j = nextJ; } else { thirdIs[j] = true; nextJ = thirdNext[j]; thirdNext[j] = max(thirdNext[j], to+1); j = nextJ; } } } for(int i = 0; i < n; i++) if(oneIs[i] && secondIs[i] && !thirdIs[i]) result++; cout << result; return 0; } |