#include <bits/stdc++.h>
// author : aykhn
using namespace std;
typedef long long ll;
#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcount
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define int ll
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F
const int MXN = 1e6 + 5;
const int B = 874;
int n;
string s;
deque<char> dq[B];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int q;
cin >> n >> q;
cin >> s;
int j = 0;
for (int i = 0; i < s.length(); i++)
{
if (i && i % B == 0) j++;
dq[j].push_back(s[i]);
}
while (q--)
{
char ch;
cin >> ch;
if (ch == 'a')
{
int l, r;
cin >> l >> r;
if (l == r) continue;
l--;
r--;
int type = 0;
if (l > r)
{
type = 1;
swap(l, r);
}
if (!type)
{
int j = l/B;
int id = l - j * B;
int k = 0;
auto it = dq[j].begin();
while (k++ < id) it++;
char del = *it;
dq[j].erase(it);
for (int i = j + 1; i <= r/B; i++)
{
dq[i - 1].push_back(dq[i].front());
dq[i].pop_front();
}
j = r/B;
id = r - j * B;
k = 0;
auto it1 = dq[j].begin();
while (k++ < id) it1++;
dq[j].ins(it1, del);
}
else
{
int j = r/B;
int id = r - j * B;
int k = 0;
auto it = dq[j].begin();
while (k++ < id) it++;
char del = *it;
dq[j].erase(it);
for (int i = j - 1; i >= l/B; i--)
{
dq[i + 1].push_front(dq[i].back());
dq[i].pop_back();
}
id = l - l/B*B;
k = 0;
auto it1 = dq[l/B].begin();
while (k++ < id) it1++;
dq[l/B].ins(it1, del);
}
}
else
{
int id;
cin >> id;
id--;
int j = id/B;
id -= j*B;
int k = 0;
auto it = dq[j].begin();
while (k++ < id) it++;
cout << *it << '\n';
}
}
}
Compilation message
collider.cpp: In function 'int main()':
collider.cpp:36:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i = 0; i < s.length(); i++)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
6 ms |
1052 KB |
Output is correct |
3 |
Correct |
4 ms |
1116 KB |
Output is correct |
4 |
Runtime error |
6 ms |
4276 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |