Submission #880692

# Submission time Handle Problem Language Result Execution time Memory
880692 2023-11-29T21:24:12 Z alexdd Collider (IZhO11_collider) C++17
100 / 100
63 ms 2644 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();
    }
    while(1)
        n=0;
    return {-1,-1};
}
void afis()
{
    for(int i=1;i<=cntv;i++)
    {
        for(auto x:v[i])
            cout<<x<<" ";
    }
    cout<<"\n";
}
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);
            char cop = v[undea.first][undea.second];
                if(undea.first < undeb.first)
                    undeb.second++;
            v[undea.first].erase(v[undea.first].begin()+undea.second);
            //afis();
            v[undeb.first].insert(v[undeb.first].begin()+undeb.second, cop);
            //afis();
        }
    }
    return 0;
}
/**
xzxyyzxxzxyyzyx
xzxyyzxxzxyyzyx
123456789
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 6 ms 348 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 33 ms 2112 KB Output is correct
5 Correct 43 ms 2408 KB Output is correct
6 Correct 46 ms 2380 KB Output is correct
7 Correct 49 ms 2564 KB Output is correct
8 Correct 40 ms 2388 KB Output is correct
9 Correct 54 ms 2644 KB Output is correct
10 Correct 63 ms 2484 KB Output is correct