#include <bits/stdc++.h> #ifdef SIO #define dbg(name) cerr << #name ": " << (name) << "\t" #define nl cerr<<endl #else #define dbg(name) #define nl #endif #define st first #define nd second #define pb push_back #define rep(i,begin,end) for(__typeof(end) i = begin; i <= end; i++) using namespace std; using ll = long long; using pii = pair<int,int>; const ll nax = 1e18+33; struct event { int kol[5]; event() { rep(i,1,3) { kol[i] = 0; } } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin >> n >> m; vector<event> v(n+3); // 1 zolty, 2 niebieski, 3 czerwony rep(i,1,m) { int l,r,k; cin >> l >> r >> k; v[l].kol[k]++; v[r+1].kol[k]--; } int akt[4], ans = 0; rep(i,1,3) akt[i] = 0; rep(i,1,n) { rep(j,1,3) { akt[j] += v[i].kol[j]; } if(akt[1] && akt[2] && !akt[3]) ans++; } cout << ans << endl; }
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 | #include <bits/stdc++.h> #ifdef SIO #define dbg(name) cerr << #name ": " << (name) << "\t" #define nl cerr<<endl #else #define dbg(name) #define nl #endif #define st first #define nd second #define pb push_back #define rep(i,begin,end) for(__typeof(end) i = begin; i <= end; i++) using namespace std; using ll = long long; using pii = pair<int,int>; const ll nax = 1e18+33; struct event { int kol[5]; event() { rep(i,1,3) { kol[i] = 0; } } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin >> n >> m; vector<event> v(n+3); // 1 zolty, 2 niebieski, 3 czerwony rep(i,1,m) { int l,r,k; cin >> l >> r >> k; v[l].kol[k]++; v[r+1].kol[k]--; } int akt[4], ans = 0; rep(i,1,3) akt[i] = 0; rep(i,1,n) { rep(j,1,3) { akt[j] += v[i].kol[j]; } if(akt[1] && akt[2] && !akt[3]) ans++; } cout << ans << endl; } |