# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
537947 | GioChkhaidze | Collider (IZhO11_collider) | C++14 | 1 ms | 468 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>
using namespace std;
string s;
int n, m, bs = 1000;
vector < int > v[10003];
main () {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n >> m >> s;
for (int i = 0; i < s.size(); ++i) {
v[i / bs].push_back(i);
}
int ms = (s.size() - 1) / bs + 1;
for (int i = 1; i <= m; ++i) {
char c;
cin >> c;
if (c == 'a') {
int id = 0, l, r;
cin >> l >> r; --l, --r;
if (l < r) --r;
for (int b = 0; b < ms; ++b) {
if (!v[b].size()) continue;
if (v[b].size() <= l) {
l -= v[b].size();
}
else {
id = v[b][l];
v[b].erase(v[b].begin() + l);
break;
}
}
for (int b = 0; b < ms; ++b) {
if (!v[b].size()) continue;
if (v[b].size() <= r) {
r -= v[b].size();
}
else {
v[b].insert(v[b].begin() + r, id);
break;
}
}
}
else
if (c == 'q') {
int x;
cin >> x; --x;
for (int b = 0; b < ms; ++b) {
if (!v[b].size()) continue;
if (v[b].size() <= x) {
x -= v[b].size();
}
else {
cout << s[v[b][x]] << "\n";
break;
}
}
}
if (i % bs == 0) {
vector < int > rec;
for (int b = 0; b < ms; ++b) {
for (int j = 0; j < v[b].size(); ++j) {
rec.push_back(v[b][j]);
}
v[b].clear();
}
for (int j = 0; j < rec.size(); ++j) {
v[j / bs].push_back(rec[j]);
}
rec.clear();
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |