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