#include <iostream>
using namespace std;
int tab[15]={0};
int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int n,m,w=0;
int l,r,k;
cin>>n>>m;
char p[n+1];
for(int i=0;i<=n;i++)p[i]=0;
for(int i=0;i<m;i++){
cin>>l>>r>>k;
for(int j=l;j<=r;j++){
if(p[j]==0)p[j]=k;
else if((p[j]==1 && k==2)||(p[j]==2 && k==1)){
p[j]=4;
w++;
}
else if(p[j]==4 && k==3){
p[j]=3;
w--;
}else if(k==3)p[j]=3;
}
}
cout<<w;
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 | #include <iostream> using namespace std; int tab[15]={0}; int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n,m,w=0; int l,r,k; cin>>n>>m; char p[n+1]; for(int i=0;i<=n;i++)p[i]=0; for(int i=0;i<m;i++){ cin>>l>>r>>k; for(int j=l;j<=r;j++){ if(p[j]==0)p[j]=k; else if((p[j]==1 && k==2)||(p[j]==2 && k==1)){ p[j]=4; w++; } else if(p[j]==4 && k==3){ p[j]=3; w--; }else if(k==3)p[j]=3; } } cout<<w; return 0; } |
English