1. 程式人生 > >2018牛客網暑期ACM多校訓練營(第三場)C Shuffle Cards(可持久化平衡樹/splay)

2018牛客網暑期ACM多校訓練營(第三場)C Shuffle Cards(可持久化平衡樹/splay)

car 訓練營 shu cas queue math getchar() %d fir

題意

牌面初始是1到n,進行m次洗牌,每次抽取一段放到最前面。求最後的序列。

分析

神操作!!!比賽時很絕望,splay技能尚未點亮,不知道怎麽用。

殊不知,C++庫裏有rope神器,即塊狀鏈表。

基礎函數

#include <ext/rope>
using namespace __gnu_cxx;

rope test;

test.push_back(x);//在末尾添加x
test.insert(pos,x);//在pos插入x  
test.erase(pos,x);//從pos開始刪除x個
test.copy(pos,len,x);//從pos開始到pos+len為止用x代替
test.replace(pos,x);//從pos開始換成x test.substr(pos,x);//提取pos開始x個 test.at(x)/[x];//訪問第x個元素

有了上面的函數,就解決這道題了(狗頭。

#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include
<set> #include<ext/rope> #define rep(i,e) for(int i=0;i<(e);i++) #define rep1(i,e) for(int i=1;i<=(e);i++) #define repx(i,x,e) for(int i=(x);i<=(e);i++) #define X first #define Y second #define PB push_back #define MP make_pair #define mset(var,val) memset(var,val,sizeof(var)) #define
scd(a) scanf("%d",&a) #define scdd(a,b) scanf("%d%d",&a,&b) #define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c) #define pd(a) printf("%d\n",a) #define scl(a) scanf("%lld",&a) #define scll(a,b) scanf("%lld%lld",&a,&b) #define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c) #define IOS ios::sync_with_stdio(false);cin.tie(0) #define lc idx<<1 #define rc idx<<1|1 #define rson mid+1,r,rc #define lson l,mid,lc using namespace std; typedef long long ll; int read() { int x = 0; char c = getchar(); while (c < 0 || c > 9)c = getchar(); while (c >= 0 && c <= 9) { x = x * 10 + c - 0; c = getchar(); } return x; } template <class T> void test(T a){cout<<a<<endl;} template <class T,class T2> void test(T a,T2 b){cout<<a<<" "<<b<<endl;} template <class T,class T2,class T3> void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;} const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fll; const ll mod = 1e9+7; int T; void testcase(){ printf("Case %d: ",++T); } const int MAXN = 1e5+10; const int MAXM = 30; const double eps = 1e-9; using namespace __gnu_cxx; int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif // LOCAL int n,m; n=read();m=read(); rope<int> ro; for(int i=1;i<=n;i++) ro.push_back(i); int x,y; while(m--){ x=read();y=read(); ro=ro.substr(x-1,y)+ro.substr(0,x-1)+ro.substr(y+x-1,n-x-y+1); } for(int i=0;i<n;i++){ printf("%d%c",ro[i],(i==n-1?\n: )); } return 0; }

2018牛客網暑期ACM多校訓練營(第三場)C Shuffle Cards(可持久化平衡樹/splay)