답안 #880689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880689 2023-11-29T21:04:35 Z alexdd 입자 가속기 (IZhO11_collider) C++17
0 / 100
1 ms 344 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int buc = 1000;
int n,m;
int cntv=1;
vector<char> v[1100];
pair<int,int> get_poz(int a)
{
    int cntp=0;
    for(int i=1;i<=cntv;i++)
    {
        if(cntp+(int)v[i].size()>=a)
        {
            return {i,a-cntp-1};
        }
        cntp += (int)v[i].size();
    }
    return {-1,-1};
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m;
    char ch;
    for(int i=1;i<=n;i++)
    {
        cin>>ch;
        if(i%buc==0)
            cntv++;
        v[cntv].push_back(ch);
    }
    int a,b;
    while(m--)
    {
        cin>>ch;
        if(ch=='q')
        {
            cin>>a;
            pair<int,int> unde = get_poz(a);
            cout<<v[unde.first][unde.second]<<"\n";
        }
        else
        {
            cin>>a>>b;
            if(a==b)
                continue;
            pair<int,int> undea = get_poz(a);
            pair<int,int> undeb = get_poz(b);
            if(undea.first!=undeb.first || undea.second > undeb.second)
            {
                char cop = v[undea.first][undea.second];
                v[undea.first].erase(v[undea.first].begin()+undea.second);
                v[undeb.first].insert(v[undeb.first].begin()+undeb.second, cop);
            }
            else
            {
                char cop = v[undea.first][undea.second];
                v[undeb.first].insert(v[undeb.first].begin()+undeb.second, cop);
                v[undea.first].erase(v[undea.first].begin()+undea.second);
            }
        }
    }
    return 0;
}
/**
xzxyyzxxzxyyzyx
xzxyyzxxzxyyzyx
123456789
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -