// Jakub Daszkiewicz
// zadanie Mieszanie kolorów [B]
#include <stdio.h>
const int N = 1 << 21;
int st = 1;
int t[3][N];
void add(int tree[], int s, int e) // color, start bucket, end bucket
{
s += st;
e += st;
while (s < e)
{
if (s & 1)
{
tree[s]++;
s >>= 1;
s++;
}
else
s >>= 1;
if (e & 1)
e >>= 1;
else
{
tree[e]++;
e >>= 1;
e--;
}
}
if (s == e)
{
tree[s]++;
}
}
int check(int tree[], int i) // color, bucket
{
int r = 0;
i += st;
while (i)
{
r += tree[i];
i >>= 1;
}
return r;
}
int main()
{
int n, m;
scanf("%d %d", &n, &m);
while (st < n)
st <<= 1;
int l, r, k;
for (int i = 0; i < m; i++)
{
scanf("%d %d %d", &l, &r, &k);
add(t[k - 1], l - 1, r - 1);
}
int a = 0;
for (int i = 0; i < n; i++)
{
if (check(t[0], i) > 0 && check(t[1], i) > 0 && check(t[2], i) <= 0)
a++;
}
printf("%d", a);
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 70 71 | // Jakub Daszkiewicz // zadanie Mieszanie kolorów [B] #include <stdio.h> const int N = 1 << 21; int st = 1; int t[3][N]; void add(int tree[], int s, int e) // color, start bucket, end bucket { s += st; e += st; while (s < e) { if (s & 1) { tree[s]++; s >>= 1; s++; } else s >>= 1; if (e & 1) e >>= 1; else { tree[e]++; e >>= 1; e--; } } if (s == e) { tree[s]++; } } int check(int tree[], int i) // color, bucket { int r = 0; i += st; while (i) { r += tree[i]; i >>= 1; } return r; } int main() { int n, m; scanf("%d %d", &n, &m); while (st < n) st <<= 1; int l, r, k; for (int i = 0; i < m; i++) { scanf("%d %d %d", &l, &r, &k); add(t[k - 1], l - 1, r - 1); } int a = 0; for (int i = 0; i < n; i++) { if (check(t[0], i) > 0 && check(t[1], i) > 0 && check(t[2], i) <= 0) a++; } printf("%d", a); return 0; } |
English