# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
481258 | FatihSolak | Collider (IZhO11_collider) | C++17 | 289 ms | 1072 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>
#define N 1005
using namespace std;
const int block_size = N;
deque<char> block[N];
void solve(){
int n,m;
cin >> n >> m;
string s;
cin >> s;
for(int i=0;i<n;i++){
block[i/block_size].push_back(s[i]);
}
while(m--){
char type;
cin >> type;
if(type == 'a'){
int a,b;
cin >> a >> b;
a--;
b--;
vector<char> tmp;
char add;
for(int i = 0;block[a/block_size].size();i++){
if(i != a%block_size){
tmp.push_back(block[a/block_size].front());
}
else add = block[a/block_size].front();
block[a/block_size].pop_front();
}
for(auto u:tmp){
block[a/block_size].push_back(u);
}
if(block[a/block_size + 1].size()){
block[a/block_size].push_back(block[a/block_size + 1].front());
}
for(int i=a/block_size + 1;block[i].size();i++){
block[i].pop_front();
if(block[i+1].size()){
block[i].push_back(block[i+1].front());
}
}
tmp.clear();
char last = '.';
for(int i = 0;block[b/block_size].size();i++){
if(i == b%block_size)tmp.push_back(add);
if(tmp.size() < block_size){
tmp.push_back(block[b/block_size].front());
}
else last = block[b/block_size].front();
block[b/block_size].pop_front();
}
for(auto u:tmp){
block[b/block_size].push_back(u);
}
for(int i=b/block_size + 1;last != '.';i++){
block[i].push_front(last);
if(block[i].size() > block_size){
last = block[i].back();
block[i].pop_back();
}
else last = '.';
}
}
if(type == 'q'){
int pos;
cin >> pos;
pos--;
cout << block[pos/block_size][pos%block_size] << endl;
}
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |