// Karol Kosinski 2020 #include <cstdio> #include <algorithm> #define FOR(i,a,b) for(int i=(a);i<(b);++i) //#define DEBUG(x...) printf(x) #define DEBUG(x...) using namespace std; const int NX = 1'000'001; struct I { int left, right; }; bool operator < (const I& a, const I& b) { return a.left - b.left < 0; } bool cans[NX]; int ends[3]; I intervals[3][NX]; void choose(int n, int ind, bool filler) { int e = ends[ind], ci = 0; FOR(j,0,e) { const auto& val = intervals[ind][j]; while (ci < val.left) { cans[ci] = cans[ci] and not filler; ++ ci; } while (ci <= val.right) { cans[ci] = cans[ci] and filler; ++ ci; } } while (ci < n) { cans[ci] = cans[ci] and not filler; ++ ci; } } int main() { int n, m, res = 0; scanf("%d%d", &n, &m); fill(cans, cans + n, true); FOR(i,0,m) { int l, r, k; scanf("%d%d%d", &l, &r, &k); -- k; intervals[ k ][ ends[k] ++ ] = (I) { l - 1, r - 1 }; } FOR(i,0,3) { sort(&intervals[i][0], &intervals[i][ends[i]]); } choose(n, 2, false); choose(n, 1, true); choose(n, 0, true); FOR(i,0,n) if (cans[i]) { DEBUG("%d ", i); ++ res; } DEBUG("\n"); 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | // Karol Kosinski 2020 #include <cstdio> #include <algorithm> #define FOR(i,a,b) for(int i=(a);i<(b);++i) //#define DEBUG(x...) printf(x) #define DEBUG(x...) using namespace std; const int NX = 1'000'001; struct I { int left, right; }; bool operator < (const I& a, const I& b) { return a.left - b.left < 0; } bool cans[NX]; int ends[3]; I intervals[3][NX]; void choose(int n, int ind, bool filler) { int e = ends[ind], ci = 0; FOR(j,0,e) { const auto& val = intervals[ind][j]; while (ci < val.left) { cans[ci] = cans[ci] and not filler; ++ ci; } while (ci <= val.right) { cans[ci] = cans[ci] and filler; ++ ci; } } while (ci < n) { cans[ci] = cans[ci] and not filler; ++ ci; } } int main() { int n, m, res = 0; scanf("%d%d", &n, &m); fill(cans, cans + n, true); FOR(i,0,m) { int l, r, k; scanf("%d%d%d", &l, &r, &k); -- k; intervals[ k ][ ends[k] ++ ] = (I) { l - 1, r - 1 }; } FOR(i,0,3) { sort(&intervals[i][0], &intervals[i][ends[i]]); } choose(n, 2, false); choose(n, 1, true); choose(n, 0, true); FOR(i,0,n) if (cans[i]) { DEBUG("%d ", i); ++ res; } DEBUG("\n"); printf("%d\n", res); return 0; } |