Submission #481262

# Submission time Handle Problem Language Result Execution time Memory
481262 2021-10-20T07:30:08 Z FatihSolak Collider (IZhO11_collider) C++17
0 / 100
181 ms 202312 KB
#include <bits/stdc++.h>
#define N 300005
#define M 1005
using namespace std;
const int block_size = 4;
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 = '.';
            }
            /*
            for(int j=0;block[j].size();j++){
                for(int i=0;i<block[j].size();i++){
                    cout << block[j][i];
                }   
            }
            cout << endl;*/
        }
        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
1 Correct 140 ms 202248 KB Output is correct
2 Incorrect 181 ms 202312 KB Output isn't correct
3 Halted 0 ms 0 KB -