#include<bits/stdc++.h> #define f first #define s second #define mp make_pair #define pb push_back #define pii pair<int, int> #define pll pair<long long, long long> #define ll long long #define vi vector<int> #define vl vector<ll> #define rep(i,p,k) for(ll i=p; i<k; i++) #define per(i,p,k) for (ll i=k-1;i>=p;i--) ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;} using namespace std; vector<pii>tab[1000005]; int kolory[4]; int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; rep(i, 0, m) { int l, r, k; cin >> l >> r >> k; tab[l].pb(mp(k, 1)); tab[r+1].pb(mp(k, -1)); } int wyn = 0; rep(i, 1, n+1) { rep(j, 0, tab[i].size()) { kolory[tab[i][j].f] += tab[i][j].s; } if(kolory[1] > 0 && kolory[2] > 0 && kolory[3] == 0) wyn++; } cout<<wyn<<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 | #include<bits/stdc++.h> #define f first #define s second #define mp make_pair #define pb push_back #define pii pair<int, int> #define pll pair<long long, long long> #define ll long long #define vi vector<int> #define vl vector<ll> #define rep(i,p,k) for(ll i=p; i<k; i++) #define per(i,p,k) for (ll i=k-1;i>=p;i--) ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;} using namespace std; vector<pii>tab[1000005]; int kolory[4]; int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; rep(i, 0, m) { int l, r, k; cin >> l >> r >> k; tab[l].pb(mp(k, 1)); tab[r+1].pb(mp(k, -1)); } int wyn = 0; rep(i, 1, n+1) { rep(j, 0, tab[i].size()) { kolory[tab[i][j].f] += tab[i][j].s; } if(kolory[1] > 0 && kolory[2] > 0 && kolory[3] == 0) wyn++; } cout<<wyn<<endl; } |