#include <bits/stdc++.h> using namespace std; struct w { int k, co; }; int n, m, s[1000001][3], k[1000001][3], aw[3], wyn; int main() { scanf("%d%d", &n, &m); for(int i = 0; i < m; i++) { int l, p, kol; scanf("%d%d%d", &l, &p, &kol); s[l][kol - 1]++; k[p][kol - 1]++; } for(int i = 1; i <= n; i++) { aw[0] += s[i][0]; aw[1] += s[i][1]; aw[2] += s[i][2]; if(aw[0] > 0 && aw[1] > 0 && aw[2] == 0) wyn++; aw[0] -= k[i][0]; aw[1] -= k[i][1]; aw[2] -= k[i][2]; } printf("%d", wyn); }
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 | #include <bits/stdc++.h> using namespace std; struct w { int k, co; }; int n, m, s[1000001][3], k[1000001][3], aw[3], wyn; int main() { scanf("%d%d", &n, &m); for(int i = 0; i < m; i++) { int l, p, kol; scanf("%d%d%d", &l, &p, &kol); s[l][kol - 1]++; k[p][kol - 1]++; } for(int i = 1; i <= n; i++) { aw[0] += s[i][0]; aw[1] += s[i][1]; aw[2] += s[i][2]; if(aw[0] > 0 && aw[1] > 0 && aw[2] == 0) wyn++; aw[0] -= k[i][0]; aw[1] -= k[i][1]; aw[2] -= k[i][2]; } printf("%d", wyn); } |