#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <vector>
using namespace std;
#define sz(s) (int)(s.size())
#define eb emplace_back
const int N = 2e5 + 5;
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
s = "#" + s;
while(m--) {
char type;
cin >> type;
if (type == 'a') {
int l, r;
cin >> l >> r;
if (l > r) {
swap(l, r);
char x = s[r];
for (int i = r - 1; i >= l; -- i)
s[i + 1] = s[i];
s[l] = x;
}
else if (l <= r) {
char x = s[l];
for (int i = l + 1; i <= r; ++ i)
s[i - 1] = s[i];
s[r] = x;
}
}
else {
int pos;
cin >> pos;
cout << s[pos] << '\n';
}
}
}
int main () {
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
25 ms |
256 KB |
Output is correct |
3 |
Correct |
431 ms |
504 KB |
Output is correct |
4 |
Execution timed out |
2058 ms |
1968 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |