#include <bits/stdc++.h> using namespace std; #define st first #define nd second #define PB push_back #define mp make_pair #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using ll = long long; constexpr int maxn = 1e6+9; int r[maxn], y[maxn], b[maxn]; int main() { fastio int n, m, left, right, ktory; cin>>n>>m; ///1->y, 2->b, 3->r while(m--){ cin>>left>>right>>ktory; if(ktory==1){ y[left]++; y[right+1]--; } else if(ktory==2){ b[left]++; b[right+1]--; } else{ r[left]++; r[right+1]--; } } int liczr=0, liczb=0, liczy=0, wyn=0; for(int i=1; i<=n; ++i){ liczr+=r[i]; liczb+=b[i]; liczy+=y[i]; if((liczr==0) && (liczy>=1) && (liczb>=1)){ wyn++; } } cout<<wyn; 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 | #include <bits/stdc++.h> using namespace std; #define st first #define nd second #define PB push_back #define mp make_pair #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using ll = long long; constexpr int maxn = 1e6+9; int r[maxn], y[maxn], b[maxn]; int main() { fastio int n, m, left, right, ktory; cin>>n>>m; ///1->y, 2->b, 3->r while(m--){ cin>>left>>right>>ktory; if(ktory==1){ y[left]++; y[right+1]--; } else if(ktory==2){ b[left]++; b[right+1]--; } else{ r[left]++; r[right+1]--; } } int liczr=0, liczb=0, liczy=0, wyn=0; for(int i=1; i<=n; ++i){ liczr+=r[i]; liczb+=b[i]; liczy+=y[i]; if((liczr==0) && (liczy>=1) && (liczb>=1)){ wyn++; } } cout<<wyn; return 0; } |