#include <iostream> #include <map> std::map<int, int> changeC, changeZ, changeN; int main() { int n, q, C = 0, Z = 0, N = 0, suma = 0; std::cin>>n>>q; int l, r, k; for(int a = 0; a < q; a++){ std::cin>>l>>r>>k; if(k == 1){ changeZ[l]++; changeZ[r+1]--; } else if(k == 2){ changeN[l]++; changeN[r+1]--; } else{ changeC[l]++; changeC[r+1]--; } } for(int a = 1; a <= n; a++){ Z += changeZ[a]; C += changeC[a]; N += changeN[a]; //std::cout<<Z<<" "<<N<<" "<<C<<"\n"; if(Z >= 1 && N >= 1 && C == 0) suma++; } std::cout<<suma; }
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> #include <map> std::map<int, int> changeC, changeZ, changeN; int main() { int n, q, C = 0, Z = 0, N = 0, suma = 0; std::cin>>n>>q; int l, r, k; for(int a = 0; a < q; a++){ std::cin>>l>>r>>k; if(k == 1){ changeZ[l]++; changeZ[r+1]--; } else if(k == 2){ changeN[l]++; changeN[r+1]--; } else{ changeC[l]++; changeC[r+1]--; } } for(int a = 1; a <= n; a++){ Z += changeZ[a]; C += changeC[a]; N += changeN[a]; //std::cout<<Z<<" "<<N<<" "<<C<<"\n"; if(Z >= 1 && N >= 1 && C == 0) suma++; } std::cout<<suma; } |