#include<bits/stdc++.h> using namespace std; vector<pair<int, int>> v[1000007]; int n, m; int cnt[7]; int res = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int l, r, k; cin >>n>>m; for (int i=0; i<m; i++){ cin >> l >> r >>k; v[l].push_back(make_pair(r, k)); } for (int i=1; i<=n; i++){ for (auto rk : v[i]){ cnt[rk.second] = max(cnt[rk.second], rk.first); } if (cnt[1]>=i && cnt[2]>= i && cnt[3]< i ) res++; } cout <<res<<"\n"; }
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 | #include<bits/stdc++.h> using namespace std; vector<pair<int, int>> v[1000007]; int n, m; int cnt[7]; int res = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int l, r, k; cin >>n>>m; for (int i=0; i<m; i++){ cin >> l >> r >>k; v[l].push_back(make_pair(r, k)); } for (int i=1; i<=n; i++){ for (auto rk : v[i]){ cnt[rk.second] = max(cnt[rk.second], rk.first); } if (cnt[1]>=i && cnt[2]>= i && cnt[3]< i ) res++; } cout <<res<<"\n"; } |