-
Notifications
You must be signed in to change notification settings - Fork 0
/
rope.cpp
44 lines (39 loc) · 893 Bytes
/
rope.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// BOJ 16994 로프와 쿼리
#include <iostream>
#include <bits/stdc++.h>
#include <ext/rope>
#define sz size()
#define bk back()
#define fi first
#define se second
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef pair<int, int> pii;
crope R;
string S;
int N, Q;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> S >> Q;
R.append(S.c_str());
N = S.sz;
while (Q--) {
int q;
cin >> q;
if (q == 1) {
int x, y;
cin >> x >> y;
R = R.substr(x, y - x + 1) + R.substr(0, x) + R.substr(y + 1, N);
} else if (q == 2) {
int x, y;
cin >> x >> y;
R = R.substr(0, x) + R.substr(y + 1, N) + R.substr(x, y - x + 1);
} else {
int x;
cin >> x;
cout << R[x] << '\n';
}
}
}