#include <bits/stdc++.h> using namespace std; #define maxn (int)1e6+100 #define mp make_pair #define pb push_back int n, m, colors[5], result; vector< pair<int, bool> > v[maxn]; int main() { scanf("%d%d", &n, &m); int l, r, k; for (int i = 0; i < m; i++) { scanf("%d%d%d", &l, &r, &k); v[l].pb(mp(k, 0)); v[r].pb(mp(k, 1)); } for (int i = 1; i <= n; i++) { for (int o = 0; o < (int)v[i].size(); o++) { if (v[i][o].second == 0) { colors[v[i][o].first]++; } } if (colors[1] > 0 && colors[2] > 0 && colors[3] == 0) result++; for (int o = 0; o < (int)v[i].size(); o++) { if (v[i][o].second == 1) { colors[v[i][o].first]--; } } } printf("%d", result); }
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 | #include <bits/stdc++.h> using namespace std; #define maxn (int)1e6+100 #define mp make_pair #define pb push_back int n, m, colors[5], result; vector< pair<int, bool> > v[maxn]; int main() { scanf("%d%d", &n, &m); int l, r, k; for (int i = 0; i < m; i++) { scanf("%d%d%d", &l, &r, &k); v[l].pb(mp(k, 0)); v[r].pb(mp(k, 1)); } for (int i = 1; i <= n; i++) { for (int o = 0; o < (int)v[i].size(); o++) { if (v[i][o].second == 0) { colors[v[i][o].first]++; } } if (colors[1] > 0 && colors[2] > 0 && colors[3] == 0) result++; for (int o = 0; o < (int)v[i].size(); o++) { if (v[i][o].second == 1) { colors[v[i][o].first]--; } } } printf("%d", result); } |