Advertisement
cosenza987

Untitled

Dec 5th, 2023
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. //Слава Україні, Героям слава
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. using ll = long long;
  8.  
  9. int main() {
  10.     ios_base::sync_with_stdio(false);
  11.     cin.tie(nullptr);
  12.     freopen("in.txt", "r", stdin);
  13.     freopen("out.txt", "w", stdout);
  14.     int n;
  15.     cin >> n;
  16.     set<pair<ll, ll>> s;
  17.     for(int i = 0; i < n; i += 2) {
  18.         ll a, b;
  19.         cin >> a >> b;
  20.         s.insert({a, a + b - 1});
  21.     }
  22.     int q;
  23.     cin >> q;
  24.     vector<set<pair<pair<ll, ll>, pair<ll, ll>>>> v(q);
  25.     for(int i = 0; i < q; i++) {
  26.         int m;
  27.         cin >> m;
  28.         for(int j = 0; j < m; j++) {
  29.             ll a, b, c;
  30.             cin >> b >> a >> c;
  31.             v[i].insert({{a, a + c - 1}, {b, b + c - 1}});
  32.         }
  33.     }
  34.     for(int i = 0; i < q; i++) {
  35.         set<pair<ll, ll>> tmp;
  36.         while(!s.empty()) {
  37.             auto x = *s.begin();
  38.             s.erase(s.begin());
  39.             auto itr = v[i].lower_bound({{x.first + 1, 0}, {0, 0}});
  40.             if(itr == v[i].begin()) {
  41.                 tmp.insert(x);
  42.                 continue;
  43.             }
  44.             itr--;
  45.             if(x.second < itr->first.first or x.first > itr->first.second) {
  46.                 tmp.insert(x);
  47.                 continue;
  48.             }
  49.             if(x.second <= itr->first.second) {
  50.                 ll diff = itr->second.first - itr->first.first;
  51.                 x.first += diff;
  52.                 x.second += diff;
  53.                 tmp.insert(x);
  54.                 continue;
  55.             }
  56.             ll diff = itr->second.first - itr->first.first;
  57.             tmp.insert({x.first + diff, itr->first.second + diff});
  58.             s.insert({itr->first.second + 1, x.second});
  59.         }
  60.         s = tmp;
  61.     }
  62.     cout << s.begin()->first << "\n";
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement