# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
859955 | aykhn | Collider (IZhO11_collider) | C++14 | 21 ms | 4856 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 998;
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |