#include <bits/stdc++.h> using namespace std; #define debug if(0) #define pb push_back #define mp make_pair #define ff first #define ss second #define ZAK 2097155 int n, m, l, r, k, R; bool tree[ZAK][4]; void insert(int x, int pp, int pk, int zp, int zk, int k) { if (pk < zp || zk < pp) { return; } if (zp <= pp && pk <= zk) { tree[x][k] = true; return; } int sr = (pp + pk) / 2; insert(x * 2, pp, sr, zp, zk, k); insert(x * 2 + 1, sr + 1, pk, zp, zk, k); } int main() { cin >> n >> m; R = 1; while (R < n) { R <<= 1; } for (int i = 1; i <= m; ++i) { cin >> l >> r >> k; insert(1, 1, R, l, r, k); } for (int i = 1; i < R; ++i) { for (int j = 1; j <= 3; ++j) { tree[i * 2][j] |= tree[i][j]; tree[i * 2 + 1][j] |= tree[i][j]; } } int wynik = 0; for (int i = 1; i <= n; ++i) { if (tree[i + R - 1][1] && tree[i + R - 1][2] && !tree[i + R - 1][3]) { ++wynik; } } printf ("%d\n", wynik); 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 | #include <bits/stdc++.h> using namespace std; #define debug if(0) #define pb push_back #define mp make_pair #define ff first #define ss second #define ZAK 2097155 int n, m, l, r, k, R; bool tree[ZAK][4]; void insert(int x, int pp, int pk, int zp, int zk, int k) { if (pk < zp || zk < pp) { return; } if (zp <= pp && pk <= zk) { tree[x][k] = true; return; } int sr = (pp + pk) / 2; insert(x * 2, pp, sr, zp, zk, k); insert(x * 2 + 1, sr + 1, pk, zp, zk, k); } int main() { cin >> n >> m; R = 1; while (R < n) { R <<= 1; } for (int i = 1; i <= m; ++i) { cin >> l >> r >> k; insert(1, 1, R, l, r, k); } for (int i = 1; i < R; ++i) { for (int j = 1; j <= 3; ++j) { tree[i * 2][j] |= tree[i][j]; tree[i * 2 + 1][j] |= tree[i][j]; } } int wynik = 0; for (int i = 1; i <= n; ++i) { if (tree[i + R - 1][1] && tree[i + R - 1][2] && !tree[i + R - 1][3]) { ++wynik; } } printf ("%d\n", wynik); return 0; } |