#include <bits/stdc++.h> using namespace std; int solve(int n, int m, vector<vector<int>> &arr) { int res = 0; for (int i = 1; i <= n; i++) { arr[i][1] += arr[i - 1][1]; arr[i][2] += arr[i - 1][2]; arr[i][3] += arr[i - 1][3]; if (arr[i][1] > 0 && arr[i][2] > 0 && arr[i][3] == 0) res++; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<vector<int>> arr(n + 9, vector<int>(5, 0)); for (int i = 1; i <= m; i++) { int l, r, x; cin >> l >> r >> x; arr[l][x]++; arr[r + 1][x]--; } cout << solve(n, m, arr) << 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 | #include <bits/stdc++.h> using namespace std; int solve(int n, int m, vector<vector<int>> &arr) { int res = 0; for (int i = 1; i <= n; i++) { arr[i][1] += arr[i - 1][1]; arr[i][2] += arr[i - 1][2]; arr[i][3] += arr[i - 1][3]; if (arr[i][1] > 0 && arr[i][2] > 0 && arr[i][3] == 0) res++; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<vector<int>> arr(n + 9, vector<int>(5, 0)); for (int i = 1; i <= m; i++) { int l, r, x; cin >> l >> r >> x; arr[l][x]++; arr[r + 1][x]--; } cout << solve(n, m, arr) << endl; } |