#include <iostream>
#include <vector>
int main()
{
std::ios_base::sync_with_stdio(false);
int n, m;
std::cin>>n>>m;
std::vector<std::vector<short>> startColorsInTans(n);
std::vector<std::vector<short>> stopColorsInTans(n);
for(int i=0; i<m; ++i)
{
int l, r, c;
std::cin>>l>>r>>c;
startColorsInTans[l-1].push_back(c);
stopColorsInTans[r-1].push_back(c);
}
int yellow_ =0, blue_=0, red_=0, count=0;
for(int i=0; i<n; ++i)
{
for(const auto& colorInTan : startColorsInTans[i])
{
switch(colorInTan)
{
case 1: ++yellow_; break;
case 2: ++blue_; break;
case 3: ++red_; break;
}
}
if(yellow_ > 0 and blue_ > 0 and red_ == 0 ) ++count;
for(const auto& colorInTan : stopColorsInTans[i])
{
switch(colorInTan)
{
case 1: --yellow_; break;
case 2: --blue_; break;
case 3: --red_; break;
}
}
}
std::cout<<count<<std::endl;
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 | #include <iostream> #include <vector> int main() { std::ios_base::sync_with_stdio(false); int n, m; std::cin>>n>>m; std::vector<std::vector<short>> startColorsInTans(n); std::vector<std::vector<short>> stopColorsInTans(n); for(int i=0; i<m; ++i) { int l, r, c; std::cin>>l>>r>>c; startColorsInTans[l-1].push_back(c); stopColorsInTans[r-1].push_back(c); } int yellow_ =0, blue_=0, red_=0, count=0; for(int i=0; i<n; ++i) { for(const auto& colorInTan : startColorsInTans[i]) { switch(colorInTan) { case 1: ++yellow_; break; case 2: ++blue_; break; case 3: ++red_; break; } } if(yellow_ > 0 and blue_ > 0 and red_ == 0 ) ++count; for(const auto& colorInTan : stopColorsInTans[i]) { switch(colorInTan) { case 1: --yellow_; break; case 2: --blue_; break; case 3: --red_; break; } } } std::cout<<count<<std::endl; return 0; } |
English