Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Introduction to ext/rope
- ///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
- #include <bits/stdc++.h>
- #include <ext/rope> /// header with rope
- using namespace std;
- using namespace __gnu_cxx; /// namespace with rope and some additional stuff
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie (NULL);
- rope <int> v; /// use as usual STL container
- int n, m;
- cin >> n >> m;
- for(int i = 1; i <= n; ++i)
- v.push_back(i); /// add elements to rope, similar to std::vector
- int l, r;
- for(int i = 0; i < m; ++i) {
- cin >> l >> r;
- --l, --r;
- rope <int> cur = v.substr (l, r - l + 1); /// subarray of rope v staring from index l to l + (r - l + 1)
- v.erase (l, r - l + 1); /// delete elements from rope v staring from index l to l + (r - l + 1)
- v.insert (v.mutable_begin(), cur); /// insert rope cur to beginning of rope v
- }
- for(int i = 0; i < v.size(); i++)
- cout << v[i] << " "; /// print elements of rope
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment