#include <cstdio> #include <vector> #include <algorithm> using namespace std; typedef pair<int, int> Cmd; Cmd mydata[3000000 + 9]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i=0; i<n; ++i) mydata[i] = Cmd(i + 1, 0); for (int i=0; i<m; ++i) { int l, r, k; scanf("%d%d%d", &l, &r, &k); mydata[n + 2 * i + 0] = Cmd(l, -k); mydata[n + 2 * i + 1] = Cmd(r, k); } n += m * 2; sort(mydata, mydata + n); int state[4]; state[1] = state[2] = state[3] = 0; int res = 0; for (int i=0; i<n; ++i) { if (mydata[i].second < 0) ++state[0 - mydata[i].second]; if (mydata[i].second > 0) --state[0 + mydata[i].second]; if (mydata[i].second == 0) { if (state[1] > 0 && state[2] > 0 && state[3] == 0) ++res; } } printf("%d\n", res); 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 | #include <cstdio> #include <vector> #include <algorithm> using namespace std; typedef pair<int, int> Cmd; Cmd mydata[3000000 + 9]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i=0; i<n; ++i) mydata[i] = Cmd(i + 1, 0); for (int i=0; i<m; ++i) { int l, r, k; scanf("%d%d%d", &l, &r, &k); mydata[n + 2 * i + 0] = Cmd(l, -k); mydata[n + 2 * i + 1] = Cmd(r, k); } n += m * 2; sort(mydata, mydata + n); int state[4]; state[1] = state[2] = state[3] = 0; int res = 0; for (int i=0; i<n; ++i) { if (mydata[i].second < 0) ++state[0 - mydata[i].second]; if (mydata[i].second > 0) --state[0 + mydata[i].second]; if (mydata[i].second == 0) { if (state[1] > 0 && state[2] > 0 && state[3] == 0) ++res; } } printf("%d\n", res); return 0; } |