Guest User

688

a guest
Aug 8th, 2017
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. /// Introduction to ext/rope
  2.  
  3. ///Solution of problem: https://www.e-olymp.com/en/problems/688 or http://informatics.mccme.ru/moodle/mod/statements/view3.php?id=1974&chapterid=2791
  4. #include <bits/stdc++.h>
  5. #include <ext/rope> /// header with rope
  6.  
  7. using namespace std;
  8. using namespace __gnu_cxx; /// namespace with rope and some additional stuff
  9.  
  10. int main() {
  11.     ios_base::sync_with_stdio(false);
  12.     cin.tie (NULL);
  13.     rope <int> v; /// use as usual STL container
  14.     int n, m;
  15.     cin >> n >> m;
  16.     for(int i = 1; i <= n; ++i)
  17.         v.push_back(i); /// add elements to rope, similar to std::vector
  18.     int l, r;
  19.     for(int i = 0; i < m; ++i) {
  20.         cin >> l >> r;
  21.         --l, --r;
  22.         rope <int> cur = v.substr (l, r - l + 1); /// subarray of rope v staring from index l to l + (r - l + 1)
  23.         v.erase (l, r - l + 1);  /// delete elements from rope v staring from index l to l + (r - l + 1)
  24.         v.insert (v.mutable_begin(), cur); /// insert rope cur to beginning of rope v
  25.     }
  26.     for(int i = 0; i < v.size(); i++)
  27.         cout << v[i] << " "; /// print elements of rope
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment