#include <cstdint>
#include <cstring>
#include <map>
#include <set>
#include <utility>
using u32 = std::uint32_t;
const u32 MAX = 1e6 + 1u;
/*
1 - START YELLOW
2 - START BLUE
3 - START RED
4 - END YELLOW
5 - END BLUE
6 - END RED
*/
u32 colors[MAX];
int main()
{
u32 n, m, l, r, k;
scanf("%u %u", &n, &m);
for(u32 i=0; i<m; ++i)
{
scanf("%u %u %u", &l, &r, &k);
colors[l] |= 1 << k;
colors[r] |= 0b1000u << k;
}
u32 Y=0, B=0, R=0;
u32 result = 0;
for(int i=1; i<MAX; ++i)
{
Y += (colors[i] >> 1) & 1u;
B += (colors[i] >> 2) & 1u;
R += (colors[i] >> 3) & 1u;
result += (Y and B and (not R));
Y -= (colors[i] >> 4) & 1u;
B -= (colors[i] >> 5) & 1u;
R -= (colors[i] >> 6) & 1u;
}
printf("%u", result);
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 | #include <cstdint> #include <cstring> #include <map> #include <set> #include <utility> using u32 = std::uint32_t; const u32 MAX = 1e6 + 1u; /* 1 - START YELLOW 2 - START BLUE 3 - START RED 4 - END YELLOW 5 - END BLUE 6 - END RED */ u32 colors[MAX]; int main() { u32 n, m, l, r, k; scanf("%u %u", &n, &m); for(u32 i=0; i<m; ++i) { scanf("%u %u %u", &l, &r, &k); colors[l] |= 1 << k; colors[r] |= 0b1000u << k; } u32 Y=0, B=0, R=0; u32 result = 0; for(int i=1; i<MAX; ++i) { Y += (colors[i] >> 1) & 1u; B += (colors[i] >> 2) & 1u; R += (colors[i] >> 3) & 1u; result += (Y and B and (not R)); Y -= (colors[i] >> 4) & 1u; B -= (colors[i] >> 5) & 1u; R -= (colors[i] >> 6) & 1u; } printf("%u", result); return 0; } |
English