Advertisement
erek1e

POI Task Rooks

Jul 9th, 2023
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <set>
  5.  
  6. using namespace std;
  7.  
  8. vector<int> solve(vector<int> x, vector<int> y) {
  9.     size_t n = x.size();
  10.     vector<pair<pair<int, int>, int>> v(n);
  11.     for (size_t i = 0; i < n; ++i) v[i] = {{y[i], x[i]}, i};
  12.     sort(v.begin(), v.end());
  13.     set<int> positions;
  14.     for (size_t i = 1; i <= n; ++i) positions.insert(i);
  15.  
  16.     vector<int> ans(n);
  17.     for (auto [pr, i] : v) {
  18.         auto [r, l] = pr;
  19.         set<int>::iterator it = positions.lower_bound(l);
  20.         if (it == positions.end() || *it > r) return {};
  21.         ans[i] = *it;
  22.         positions.erase(it);
  23.     }
  24.     return ans;
  25. }
  26.  
  27. int main() {
  28.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  29.     int n; cin >> n;
  30.     vector<int> a(n), b(n), c(n), d(n);
  31.     for (int i = 0; i < n; ++i) {
  32.         cin >> a[i] >> b[i] >> c[i] >> d[i];
  33.     }
  34.     vector<int> e = solve(a, c), f = solve(b, d);
  35.     if (e.empty() || f.empty()) cout << "NIE\n";
  36.     else {
  37.         for (int i = 0; i < n; ++i) {
  38.             cout << e[i] << ' ' << f[i] << '\n';
  39.         }
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement