#include <ctime> #include <cassert> #include <iostream> #include <cstdio> #include <iomanip> #include <vector> #include <algorithm> using namespace std; const int MAXN = 1000000; const int MAXM = 1000000; #define FOR(i, n) for(int i = 0, __n = (n); i < __n; i++) int p[MAXN+1][3]; int main() { // ios_base::sync_with_stdio(0); int n, m; // cin >> n >> m; scanf("%d%d", &n, &m); // FOR (i, n+1) FOR (j, 3) p[i][j] = 0; FOR (i, m) { int l, r, k; // cin >> l >> r >> k; scanf("%d%d%d", &l, &r, &k); p[l-1][k-1]++; p[r][k-1]--; } int sum = 0; int s[3] = {0, 0, 0}; FOR (i, n) { FOR (j, 3) s[j] += p[i][j]; // cerr << !!s[0] << !!s[1] << !!s[2] << endl; if (s[0] > 0 && s[1] > 0 && s[2] == 0) { sum++; } } cout << sum << endl; 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 | #include <ctime> #include <cassert> #include <iostream> #include <cstdio> #include <iomanip> #include <vector> #include <algorithm> using namespace std; const int MAXN = 1000000; const int MAXM = 1000000; #define FOR(i, n) for(int i = 0, __n = (n); i < __n; i++) int p[MAXN+1][3]; int main() { // ios_base::sync_with_stdio(0); int n, m; // cin >> n >> m; scanf("%d%d", &n, &m); // FOR (i, n+1) FOR (j, 3) p[i][j] = 0; FOR (i, m) { int l, r, k; // cin >> l >> r >> k; scanf("%d%d%d", &l, &r, &k); p[l-1][k-1]++; p[r][k-1]--; } int sum = 0; int s[3] = {0, 0, 0}; FOR (i, n) { FOR (j, 3) s[j] += p[i][j]; // cerr << !!s[0] << !!s[1] << !!s[2] << endl; if (s[0] > 0 && s[1] > 0 && s[2] == 0) { sum++; } } cout << sum << endl; return 0; } |