#include<bits/stdc++.h>
using namespace std;
struct event{
int czas,typ,kolor;//1-start,0-licz,-1-koniec
event(int a, int b, int c) {
czas = a; kolor = b; typ = c;
}
};
bool komp(event a, event b) {
if(a.czas != b.czas)
return a.czas < b.czas;
return a.typ > b.typ;
}
int t[4];
int n,m;
int wyn = 0;
vector<event> ev;
void wczytaj() {
int n,m; cin >> n >> m;
for(int i = 1; i <= n; i++) {
ev.emplace_back(i,0,0);
}
for(int i = 0; i < m; i++) {
int a,b,c; cin >> a >> b >> c;
ev.emplace_back(a,c,1);
ev.emplace_back(b,c,-1);
}
}
void calc() {
for(auto x : ev) {
if(x.typ == 0) {
if(t[1] && t[2] && !t[3])
wyn++;
}
if(x.typ == 1) {
t[x.kolor]++;
}
if(x.typ == -1) {
t[x.kolor]--;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
wczytaj();
sort(ev.begin(),ev.end(),komp);
calc();
cout << wyn;
}
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 | #include<bits/stdc++.h> using namespace std; struct event{ int czas,typ,kolor;//1-start,0-licz,-1-koniec event(int a, int b, int c) { czas = a; kolor = b; typ = c; } }; bool komp(event a, event b) { if(a.czas != b.czas) return a.czas < b.czas; return a.typ > b.typ; } int t[4]; int n,m; int wyn = 0; vector<event> ev; void wczytaj() { int n,m; cin >> n >> m; for(int i = 1; i <= n; i++) { ev.emplace_back(i,0,0); } for(int i = 0; i < m; i++) { int a,b,c; cin >> a >> b >> c; ev.emplace_back(a,c,1); ev.emplace_back(b,c,-1); } } void calc() { for(auto x : ev) { if(x.typ == 0) { if(t[1] && t[2] && !t[3]) wyn++; } if(x.typ == 1) { t[x.kolor]++; } if(x.typ == -1) { t[x.kolor]--; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); wczytaj(); sort(ev.begin(),ev.end(),komp); calc(); cout << wyn; } |
English