#include <bits/stdc++.h> #define PB push_back using namespace std; typedef long long int ll; typedef vector <int> vi; #define FOR(k,a,b) for(int k=(a); k < (b); ++k) const int N=1000001; ll prt = (ll)1000000007; struct seg{ int left; int right; }; struct cmp{ bool operator()(const seg& s1, const seg& s2){ return s1.right<s2.left; } }; int color(int c){ if(c==1)return 2; if(c==2)return 3; return 5; } int main() { int n,m; scanf("%d %d",&n,&m); char * t = new char[n+1]; for(int i=0;i<=n;i++){ t[i]=1; } for(int i=0;i<m;i++){ int l,r,c; scanf("%d %d %d",&l,&r,&c); int col = color(c); for(int j=l;j<=r;j++){ if(t[j]%col!=0)t[j]*=col; } } int res=0; for(int i=0;i<=n;i++){ if(t[i]==6)res++; } printf("%d",res); delete t; 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 | #include <bits/stdc++.h> #define PB push_back using namespace std; typedef long long int ll; typedef vector <int> vi; #define FOR(k,a,b) for(int k=(a); k < (b); ++k) const int N=1000001; ll prt = (ll)1000000007; struct seg{ int left; int right; }; struct cmp{ bool operator()(const seg& s1, const seg& s2){ return s1.right<s2.left; } }; int color(int c){ if(c==1)return 2; if(c==2)return 3; return 5; } int main() { int n,m; scanf("%d %d",&n,&m); char * t = new char[n+1]; for(int i=0;i<=n;i++){ t[i]=1; } for(int i=0;i<m;i++){ int l,r,c; scanf("%d %d %d",&l,&r,&c); int col = color(c); for(int j=l;j<=r;j++){ if(t[j]%col!=0)t[j]*=col; } } int res=0; for(int i=0;i<=n;i++){ if(t[i]==6)res++; } printf("%d",res); delete t; return 0; } |