#include <bits/stdc++.h> using namespace std; vector <pair <int, pair<int, int> > >dane;//kolor, lewy, prawy int wyn[1000001][3]; int main() { ios_base::sync_with_stdio(0); int kolor, i, j, l, p, l2, p2, k, k2, m, n, z = 0; pair <int, pair<int, int> > para; cin >> n >> m;//puszki, operacje for(i = 0; i < m; i++){ //cin >> l >> p >> kolor; cin >> para.second.first >> para.second.second >> para.first; dane.push_back(para); } sort(dane.begin(), dane.end()); //wyznaczanie ciagłych przedziałów k = dane[0].first; l = dane[0].second.first; p = dane[0].second.second; //cout << l <<" "<< p <<" "<< k << endl; for(i = 1; i < m; i++){ k2 = dane[i].first; l2 = dane[i].second.first; p2 = dane[i].second.second; //cout << l2 <<" "<< p2 <<" "<< k2 << endl; if(k2 == k){ if(p >= l2 - 1) { p = max(p, p2); } else { for(j = l; j <= p;j++) wyn[j][k-1] = 1; l = l2; p = p2; } } else{ for(j = l; j <= p;j++) wyn[j][k-1] = 1; l = l2; p = p2; k = k2; } } for(j = l; j <= p;j++) wyn[j][k-1] = 1; //zliczenie wyniku //k = 1 - zolty, 2 - niebieski, 3 - czerwony for(i = 1; i <= n; i++) { //cout <<wyn[i][0] <<" "<< wyn[i][1] <<" "<< wyn[i][2] <<endl; if(wyn[i][0] == 1 && wyn[i][1] == 1 && wyn[i][2] == 0) z++; } cout << z; 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 | #include <bits/stdc++.h> using namespace std; vector <pair <int, pair<int, int> > >dane;//kolor, lewy, prawy int wyn[1000001][3]; int main() { ios_base::sync_with_stdio(0); int kolor, i, j, l, p, l2, p2, k, k2, m, n, z = 0; pair <int, pair<int, int> > para; cin >> n >> m;//puszki, operacje for(i = 0; i < m; i++){ //cin >> l >> p >> kolor; cin >> para.second.first >> para.second.second >> para.first; dane.push_back(para); } sort(dane.begin(), dane.end()); //wyznaczanie ciagłych przedziałów k = dane[0].first; l = dane[0].second.first; p = dane[0].second.second; //cout << l <<" "<< p <<" "<< k << endl; for(i = 1; i < m; i++){ k2 = dane[i].first; l2 = dane[i].second.first; p2 = dane[i].second.second; //cout << l2 <<" "<< p2 <<" "<< k2 << endl; if(k2 == k){ if(p >= l2 - 1) { p = max(p, p2); } else { for(j = l; j <= p;j++) wyn[j][k-1] = 1; l = l2; p = p2; } } else{ for(j = l; j <= p;j++) wyn[j][k-1] = 1; l = l2; p = p2; k = k2; } } for(j = l; j <= p;j++) wyn[j][k-1] = 1; //zliczenie wyniku //k = 1 - zolty, 2 - niebieski, 3 - czerwony for(i = 1; i <= n; i++) { //cout <<wyn[i][0] <<" "<< wyn[i][1] <<" "<< wyn[i][2] <<endl; if(wyn[i][0] == 1 && wyn[i][1] == 1 && wyn[i][2] == 0) z++; } cout << z; return 0; } |