/* * author: pavveu * task: PA Runda 1 - Mieszanie Kolorow [B] */ #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; #define FOR(iter, val) for(int iter = 0; iter < (val); iter++) #define all(x) begin(x), end(x) void go() { int n, m; cin >> n >> m; vi colored[3]; FOR(c, 3) colored[c].assign(n, 0); FOR(q, m) { // 1 indexed int l, r, c; cin >> l >> r >> c; l--; c--; colored[c][l] += 1; if ( r < n ) colored[c][r] -= 1; } auto is_green = [&](int y, int n, int c){ return ( y > 0 && n > 0 && c == 0 ); }; FOR(c, 3) for (int i = 1; i < n; i++) colored[c][i] += colored[c][i - 1]; int green_cnt { 0 }; FOR(i, n) green_cnt += is_green(colored[0][i], colored[1][i], colored[2][i]); cout << green_cnt << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); go(); 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 | /* * author: pavveu * task: PA Runda 1 - Mieszanie Kolorow [B] */ #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; #define FOR(iter, val) for(int iter = 0; iter < (val); iter++) #define all(x) begin(x), end(x) void go() { int n, m; cin >> n >> m; vi colored[3]; FOR(c, 3) colored[c].assign(n, 0); FOR(q, m) { // 1 indexed int l, r, c; cin >> l >> r >> c; l--; c--; colored[c][l] += 1; if ( r < n ) colored[c][r] -= 1; } auto is_green = [&](int y, int n, int c){ return ( y > 0 && n > 0 && c == 0 ); }; FOR(c, 3) for (int i = 1; i < n; i++) colored[c][i] += colored[c][i - 1]; int green_cnt { 0 }; FOR(i, n) green_cnt += is_green(colored[0][i], colored[1][i], colored[2][i]); cout << green_cnt << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); go(); return 0; } |