#include <iostream> #include <stdio.h> int main() { long long int n, m; scanf("%lld %lld", &n, &m); char puszki[n][4] = {{0}}; long long int l, r; int k; for (long long i = 0; i<m; i++){ scanf("%lld %lld %d", &l, &r, &k); for(long long j = l; j<=r; j++){ puszki[j][k] = 1; } } long long int sum = 0; for (long long i = 0; i<n; i++){ if(puszki[i][1] && puszki[i][2] && !puszki[i][3]){ sum++; } } printf("%lld", sum); 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 | #include <iostream> #include <stdio.h> int main() { long long int n, m; scanf("%lld %lld", &n, &m); char puszki[n][4] = {{0}}; long long int l, r; int k; for (long long i = 0; i<m; i++){ scanf("%lld %lld %d", &l, &r, &k); for(long long j = l; j<=r; j++){ puszki[j][k] = 1; } } long long int sum = 0; for (long long i = 0; i<n; i++){ if(puszki[i][1] && puszki[i][2] && !puszki[i][3]){ sum++; } } printf("%lld", sum); return 0; } |