Advertisement
matheus_monteiro

Copying Data

Sep 16th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. #define bug(x) cout << #x << "  >>>>>>>  " << x << '\n'
  7. #define _ << " , " <<
  8. #define INF 0x3f3f3f3f
  9. #define iii pair<pair<int, int>, int>
  10. #define ii pair<int, int>
  11. #define fi first
  12. #define se second
  13.  
  14. struct ColorUpdate {
  15.     set<iii> intervals;
  16.     vector<ii> data;
  17.  
  18.     ColorUpdate() {
  19.         intervals.insert( { {-INF, INF}, -1} );
  20.     }
  21.  
  22.     void paint(int l, int r, int x, int y) {
  23.         if(l > r) return;
  24.  
  25.         int color = data.size();
  26.         data.push_back({x, y});
  27.  
  28.         auto a = prev(intervals.upper_bound({{l, INF}, INF}));
  29.         auto b = prev(intervals.upper_bound({{r, INF}, INF}));
  30.  
  31.         int l1 = a->fi.fi, r1 = l - 1, c1 = a->se;
  32.         int l2 = r + 1, r2 = b->fi.se, c2 = b->se;
  33.  
  34.         intervals.erase(a, next(b));
  35.  
  36.         if(l1 <= r1) intervals.insert({{l1, r1}, c1});
  37.         if(l2 <= r2) intervals.insert({{l2, r2}, c2});
  38.         if(l <= r) intervals.insert({{l, r}, color});
  39.     }
  40.  
  41.     int get_color_of(int x) {
  42.         return prev(intervals.upper_bound({{x, INF}, INF}))->se;
  43.     }
  44.  
  45.     ii get_pos(int i) {
  46.         int col = get_color_of(i);
  47.         if(col == -1) return {1, i};
  48.         return {0, data[col].fi - data[col].se + i};
  49.     }
  50. };
  51.  
  52. int32_t main() {
  53.  
  54.     ios_base::sync_with_stdio(false);
  55.     cin.tie(nullptr);
  56.  
  57.     int n, q;
  58.  
  59.     cin >> n >> q;
  60.  
  61.     vector<vector<int>> data(2, vector<int>(n));
  62.  
  63.     for(int i = 0; i < 2; i++)
  64.         for(int j = 0; j < n; j++)
  65.             cin >> data[i][j];
  66.  
  67.     ColorUpdate C;
  68.  
  69.     for(int i = 0; i < q; i++) {
  70.         int o;
  71.         cin >> o;
  72.         if(o == 1) {
  73.             int x, y, k;
  74.             cin >> x >> y >> k; x--; y--;
  75.             C.paint(y, y + k - 1, x, y);
  76.  
  77.         } else {
  78.             int x;
  79.             cin >> x; x--;
  80.             auto [a, b] = C.get_pos(x);
  81.             cout << data[a][b] << '\n';
  82.         }
  83.     }
  84.  
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement