C Shuffle Cards【rope+输入挂】

题意:1~n的一个初始序列,m个操作(ai, bi),表示将(ai, bi + ai - 1)区间移到最前面,让你求最后的序列;
分析:
伸展树?不会呀,直接rope+输入挂 搞过!

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include <ext/rope>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const LL INF = 1LL << 60;
const int mod = 1e9 + 7;
const int MAXN = 1e4 + 10;
rope<int> rop;//定义方式
template <class T> inline void scan_d(T &ret) {
    char c; ret = 0;
    while ((c = getchar()) < '0' || c > '9');
    while (c >= '0' && c <= '9') { 
        ret = ret * 10 + (c - '0'), c = getchar();
    }
}

int main() {
    int n, m, a, b;
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; ++i) rop.push_back(i);
    for(int i = 1; i <= m; ++i) {
        scan_d(a);
        scan_d(b);
        rop = rop.substr(a - 1, b) + rop.substr(0, a - 1) + rop.substr(a + b - 1, n - a - b + 1);//直接序列拼接
    }
    for(int i = 0; i < n; ++i) {
        printf("%d%c", rop[i], (i == n - 1) ? '\n' : ' ');
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值