#include <bits/stdc++.h> using namespace std; typedef vector<pair<int,int>> vec; void wczytaj(vec *zolte, vec *nieb, vec *czerw, int m) { int a, b, c; for (int i = 0; i < m; ++i) { cin >> a >> b >> c; if (c == 1) zolte->push_back(make_pair(a,b)); else if (c == 2) nieb->push_back(make_pair(a,b)); else czerw->push_back(make_pair(a,b)); } sort(zolte->begin(), zolte->end()); sort(nieb->begin(), nieb->end()); sort(czerw->begin(), czerw->end()); } void wypelnij(int *tab, vec v) { int kon = 0; for (int i = 0; i < (int) v.size(); ++i) { if (v[i].second > kon) { for (int j = max(kon, v[i].first); j <= v[i].second; ++j) { tab[j] = 1; } kon = v[i].second; } } } int sprawdz(int n, int m) { vec zolte, nieb, czerw; wczytaj(&zolte, &nieb, &czerw, m); int *z, *ni, *c; z = new int[n + 1](); ni = new int[n + 1](); c = new int[n + 1](); wypelnij(z, zolte); wypelnij(ni, nieb); wypelnij(c, czerw); int wynik = 0; for (int i = 0; i <= n; ++i) { if (z[i] == 1 && ni[i] == 1 && c[i] == 0) ++wynik; } delete[] z; delete[] ni; delete[] c; return wynik; } int main() { //clock_t start, end; //start = clock(); ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; cout << sprawdz(n, m) << '\n'; //end = clock(); //double time_taken = double(end - start) / double(CLOCKS_PER_SEC); //cout << "Time taken by program is : " << fixed //<< time_taken << setprecision(5); //cout << " sec " << 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 | #include <bits/stdc++.h> using namespace std; typedef vector<pair<int,int>> vec; void wczytaj(vec *zolte, vec *nieb, vec *czerw, int m) { int a, b, c; for (int i = 0; i < m; ++i) { cin >> a >> b >> c; if (c == 1) zolte->push_back(make_pair(a,b)); else if (c == 2) nieb->push_back(make_pair(a,b)); else czerw->push_back(make_pair(a,b)); } sort(zolte->begin(), zolte->end()); sort(nieb->begin(), nieb->end()); sort(czerw->begin(), czerw->end()); } void wypelnij(int *tab, vec v) { int kon = 0; for (int i = 0; i < (int) v.size(); ++i) { if (v[i].second > kon) { for (int j = max(kon, v[i].first); j <= v[i].second; ++j) { tab[j] = 1; } kon = v[i].second; } } } int sprawdz(int n, int m) { vec zolte, nieb, czerw; wczytaj(&zolte, &nieb, &czerw, m); int *z, *ni, *c; z = new int[n + 1](); ni = new int[n + 1](); c = new int[n + 1](); wypelnij(z, zolte); wypelnij(ni, nieb); wypelnij(c, czerw); int wynik = 0; for (int i = 0; i <= n; ++i) { if (z[i] == 1 && ni[i] == 1 && c[i] == 0) ++wynik; } delete[] z; delete[] ni; delete[] c; return wynik; } int main() { //clock_t start, end; //start = clock(); ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; cout << sprawdz(n, m) << '\n'; //end = clock(); //double time_taken = double(end - start) / double(CLOCKS_PER_SEC); //cout << "Time taken by program is : " << fixed //<< time_taken << setprecision(5); //cout << " sec " << endl; return 0; } |