牛客网暑期ACM多校训练营(第三场)C Shuffle Cards (STL rope)

题目大意:给出n个元素的序列,a[1]...a[n].

接下来有操作,将从第p个开始s个元素拿出来放到开头。问经过若干次操作之后的序列是?

rope参考链接:https://blog.csdn.net/qq_35649707/article/details/78828560

简单介绍rope:

类似指针链表的操作,时间复杂度会在n*(n^0.5),可以在很短的时间内实现快速的插入、删除和查找字符串

在g++头文件中,<ext/rope>中有成型的块状链表,在using namespace __gnu_cxx;空间中,类似string函数的操作其操作十分方便。

基本操作:

rope T;

T.push_back(x);//在末尾添加x

T.insert(pos,x);//在pos插入x

T.erase(pos,x);//从pos开始删除x个

T.copy(pos,len,x);//从pos开始到pos+len为止用x代替

T.replace(pos,x);//从pos开始换成x

T.substr(pos,x);//提取pos开始x个

T.at(x)/[x];//访问第x个元素

printf("%d\n",T[i])   cout<<T<<endl; 输出T[i] 输出T;

#include <iostream>
#include <cstdio>
#include <ext/rope>

using namespace __gnu_cxx;
using namespace std;

int n,m;

rope<int>a;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) a.push_back(i);
    while(m--)
    {
        int p,s;
        scanf("%d%d",&p,&s);
        p--;

        a=a.substr(p,s)+a.substr(0,p)+a.substr(p+s,n-p-s);
    }
    for(int i=0;i<n;i++) printf("%d ",a[i]);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Fy1999/p/9610206.html
今日推荐