#include <bits/stdc++.h>
using namespace std;
#define io \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
ll bp(ll n,ll m){
if(m == 0){
return 1;
}
if(m == 1){
return n;
}
if(m%2==0){
return bp(n*n,m/2);
}
return n*bp(n,m-1);
}
const int N = 1e6 + 545, M = 33, inf = 1e9 + 99;
const ll inff = 1e12;
int main() {
int n,q;
string s;
cin >> n >> q >> s;
vector<pair<int,int>>v;
while(q--) {
char typ;
cin >> typ;
if(typ == 'a') {
int x , y;
cin >> x >> y;
v.push_back({x, y});
}
else {
int ind;
cin >> ind;
for(int j=(int)v.size()-1;j >= 0;j--) {
if(v[j].second == ind) {
ind = v[j].first;
continue;
}
if(v[j].second < ind) {
ind--;
}
if(v[j].first <= ind) {
ind++;
}
}
cout << s[ind - 1] << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
55 ms |
872 KB |
Output is correct |
3 |
Correct |
15 ms |
604 KB |
Output is correct |
4 |
Correct |
32 ms |
2168 KB |
Output is correct |
5 |
Correct |
63 ms |
2064 KB |
Output is correct |
6 |
Correct |
87 ms |
2500 KB |
Output is correct |
7 |
Correct |
87 ms |
3604 KB |
Output is correct |
8 |
Correct |
28 ms |
3340 KB |
Output is correct |
9 |
Correct |
128 ms |
3604 KB |
Output is correct |
10 |
Correct |
73 ms |
3624 KB |
Output is correct |