#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct borderEdge
{
int index;
int type;
int color;
};
bool cmp(borderEdge a, borderEdge b)
{
if(a.index < b.index)
{
return true;
}else
{
return false;
}
}
int main()
{
std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
vector<borderEdge> edges;
int n,m;
cin >> n >> m;
for(int i = 0; i < m; i++)
{
int l,r,k;
cin >> l >> r >> k;
--l; r;
borderEdge tmp;
tmp.index = l;
tmp.type = 0;
tmp.color = k;
edges.push_back(tmp);
tmp.index = r;
tmp.type = 1;
edges.push_back(tmp);
}
sort(edges.begin(), edges.end(), cmp);
vector<int> Col(3, 0);
int action = 0;
int counter = 0;
for(int i = 0; i < n; i++)
{
while(edges[action].index == i)
{
if(edges[action].type == 0)
{
Col[edges[action].color - 1]++;
}
if(edges[action].type == 1)
{
Col[edges[action].color - 1]--;
}
action++;
}
if(Col[0] != 0 && Col[1] != 0 && Col[2] == 0)
{
counter++;
}
}
cout << counter << endl;
}
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 | #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; struct borderEdge { int index; int type; int color; }; bool cmp(borderEdge a, borderEdge b) { if(a.index < b.index) { return true; }else { return false; } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); vector<borderEdge> edges; int n,m; cin >> n >> m; for(int i = 0; i < m; i++) { int l,r,k; cin >> l >> r >> k; --l; r; borderEdge tmp; tmp.index = l; tmp.type = 0; tmp.color = k; edges.push_back(tmp); tmp.index = r; tmp.type = 1; edges.push_back(tmp); } sort(edges.begin(), edges.end(), cmp); vector<int> Col(3, 0); int action = 0; int counter = 0; for(int i = 0; i < n; i++) { while(edges[action].index == i) { if(edges[action].type == 0) { Col[edges[action].color - 1]++; } if(edges[action].type == 1) { Col[edges[action].color - 1]--; } action++; } if(Col[0] != 0 && Col[1] != 0 && Col[2] == 0) { counter++; } } cout << counter << endl; } |
English