답안 #481261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
481261 2021-10-20T07:28:15 Z FatihSolak 입자 가속기 (IZhO11_collider) C++17
0 / 100
138 ms 262148 KB
#include <bits/stdc++.h>
#define N 1000005
#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
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 138 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -