#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
// author : aykhn
using namespace std;
using namespace __gnu_pbds;
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
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MXN = 1e6 + 5;
const int B = 1000 + 5;
int n;
string s;
deque<char> dq[B];
string str[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]);
str[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; j++)
{
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; j--)
{
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:41: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]
41 | for (int i = 0; i < s.length(); i++)
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
6 ms |
1112 KB |
Output is correct |
3 |
Runtime error |
2 ms |
2648 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |