#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
using Range = std::pair<int, int>;
using RangeVec = std::vector<Range>;
int solve(int n, int m)
{
RangeVec yellow, blue, red;
for (int i = 0; i<m; ++i)
{
int l, r, k;
std::cin >> l >> r >> k;
if (k == 1)
{
yellow.push_back({l,r});
}
else if (k == 2)
{
blue.push_back({l,r});
}
else if (k == 3)
{
red.push_back({l,r});
}
}
auto sorter = [](RangeVec& vec)
{
std::sort(vec.begin(), vec.end(), [](Range const& fst, Range const& snd){
return (fst.first < snd.first) || (fst.first == snd.first && fst.second < snd.second);
});
};
auto printer = [](RangeVec const& vec){
for (auto const& [l, r] : vec)
{
std::cout << l << " " << r << std::endl;
}
};
sorter(blue);
sorter(yellow);
sorter(red);
std::array<int, 1000000> farba;
std::fill(farba.begin(), farba.end(), 0);
auto inserter = [&](RangeVec const& vec, int value)
{
int last = 0;
for (auto const& [l, v] : vec)
{
if (last >= v)
continue;
int i = l;
if (last >= i)
i = last+1;
for (;i<=v; ++i)
{
farba[i-1] += value;
}
last = v;
}
};
inserter(yellow, 1);
inserter(blue, 2);
inserter(red, 4);
int count = 0;
for (auto const& v : farba)
if (v == 3)
++count;
return count;
}
int main()
{
int n,m;
std::cin >> n >> m;
std::cout << solve(n,m) << 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #include <iostream> #include <string> #include <vector> #include <tuple> #include <algorithm> using Range = std::pair<int, int>; using RangeVec = std::vector<Range>; int solve(int n, int m) { RangeVec yellow, blue, red; for (int i = 0; i<m; ++i) { int l, r, k; std::cin >> l >> r >> k; if (k == 1) { yellow.push_back({l,r}); } else if (k == 2) { blue.push_back({l,r}); } else if (k == 3) { red.push_back({l,r}); } } auto sorter = [](RangeVec& vec) { std::sort(vec.begin(), vec.end(), [](Range const& fst, Range const& snd){ return (fst.first < snd.first) || (fst.first == snd.first && fst.second < snd.second); }); }; auto printer = [](RangeVec const& vec){ for (auto const& [l, r] : vec) { std::cout << l << " " << r << std::endl; } }; sorter(blue); sorter(yellow); sorter(red); std::array<int, 1000000> farba; std::fill(farba.begin(), farba.end(), 0); auto inserter = [&](RangeVec const& vec, int value) { int last = 0; for (auto const& [l, v] : vec) { if (last >= v) continue; int i = l; if (last >= i) i = last+1; for (;i<=v; ++i) { farba[i-1] += value; } last = v; } }; inserter(yellow, 1); inserter(blue, 2); inserter(red, 4); int count = 0; for (auto const& v : farba) if (v == 3) ++count; return count; } int main() { int n,m; std::cin >> n >> m; std::cout << solve(n,m) << std::endl; return 0; } |
English