Shuffle Cards

链接:https://www.nowcoder.com/acm/contest/141/C
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld

题目描述

Eddy likes to play cards game since there are always lots of randomness in the game. For most of the cards game, the very first step in the game is shuffling the cards. And, mostly the randomness in the game is from this step. However, Eddy doubts that if the shuffling is not done well, the order of the cards is predictable!

To prove that, Eddy wants to shuffle cards and tries to predict the final order of the cards. Actually, Eddy knows only one way to shuffle cards that is taking some middle consecutive cards and put them on the top of rest. When shuffling cards, Eddy just keeps repeating this procedure. After several rounds, Eddy has lost the track of the order of cards and believes that the assumption he made is wrong. As Eddy's friend, you are watching him doing such foolish thing and easily memorizes all the moves he done. Now, you are going to tell Eddy the final order of cards as a magic to surprise him.

Eddy has showed you at first that the cards are number from 1 to N from top to bottom.

For example, there are 5 cards and Eddy has done 1 shuffling. He takes out 2-nd card from top to 4-th card from top(indexed from 1) and put them on the top of rest cards. Then, the final order of cards from top will be [2,3,4,1,5].

输入描述:

The first line contains two space-separated integer N, M indicating the number of cards and the number of shuffling Eddy has done.
Each of following M lines contains two space-separated integer p

i

, s

i

 indicating that Eddy takes p

i

-th card from top to (p

i

+s

i

-1)-th card from top(indexed from 1) and put them on the top of rest cards.

1 ≤ N, M ≤ 10

5

1 ≤ p

i

 ≤ N
1 ≤ s

i

 ≤ N-p

i

+1

输出描述:

Output one line contains N space-separated integers indicating the final order of the cards from top to bottom.

输入例子:
5 1
2 3
输出例子:
2 3 4 1 5

-->

示例1

输入

复制

5 1
2 3

输出

复制

2 3 4 1 5
示例2

输入

复制

5 2
2 3
2 3

输出

复制

3 4 1 2 5
示例3

输入

复制

5 3
2 3
1 4
2 4

输出

复制

3 4 1 5 2

看成字符串处理。

STL中的rope准确的中文翻译是可持久化平衡树,超好用!

第一次用,因为内部实现是平衡树,所以时间效率较高(空间比较玄学)

貌似不是标准的STL容器,在名称空间__gnu_cxx中,用起来和string差不多

s.insert(a,b) 在s的第a位插入b(b可为字符串)

s.erase(a,b)在s的第a位删除b

输出时直接将s[c]表示s的第c位数

ps:本题与C++的string作了对比,同样的实现string43%超时,rope600ms过


#include<bits/stdc++.h>
#include<ext/rope> //固定写法
using namespace std;
using namespace __gnu_cxx; //固定写法
rope<int> s; //实质是可持久化平衡树 int main()
{
int n,m,l,e,i;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++){
s.push_back(i); //放元素
}
while(m--){
scanf("%d%d",&l,&e);
s=s.substr(l-,e)+s.substr(,l-)+s.substr(l+e-,n-e-(l-)); //将区间放置首位,重新组合数组,substr(起始字符,元素个数)
}
for(i=;i<s.size();i++){
if(i>) printf(" ");
printf("%d",s[i]); //元素按下标输出
}
return ;
}

牛客多校3 C-Shuffle Cards(rope大法解决数组分块)的更多相关文章

  1. 牛客多校第3场 J 思维+树状数组+二分

    牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...

  2. 2019牛客多校第一场 I Points Division(动态规划+线段树)

    2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...

  3. 牛客多校第一场 B Inergratiion

    牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...

  4. 2019牛客多校第二场 A Eddy Walker(概率推公式)

    2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...

  5. 牛客多校第三场 F Planting Trees

    牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...

  6. 牛客多校第三场 G Removing Stones(分治+线段树)

    牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...

  7. 牛客多校第四场sequence C (线段树+单调栈)

    牛客多校第四场sequence C (线段树+单调栈) 传送门:https://ac.nowcoder.com/acm/contest/884/C 题意: 求一个$\max {1 \leq l \le ...

  8. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

  9. 2019年牛客多校第一场B题Integration 数学

    2019年牛客多校第一场B题 Integration 题意 给出一个公式,求值 思路 明显的化简公式题,公式是分母连乘形式,这个时候要想到拆分,那如何拆分母呢,自然是裂项,此时有很多项裂项,我们不妨从 ...

随机推荐

  1. ADAS

    1 什么是ADAS advanced driver assistance system,即高级驾驶员辅助系统.是基于车上各种传感器的应用,如摄像头.雷达.激光器等. 2 ADAS的构成部分 2.1 a ...

  2. 【题解】 P5021赛道修建

    [题解]P5021 赛道修建 二分加贪心,轻松拿省一(我没有QAQ) 题干有提示: 输出格式: 输出共一行,包含一个整数,表示长度最小的赛道长度的最大值. 注意到没,最小的最大值,还要多明显? 那么我 ...

  3. UVa 10828 Back to Kernighan-Ritchie 高斯消元+概率DP

    题目来源:UVa 10828 Back to Kernighan-Ritchie 题意:从1開始 每次等概率从一个点到和他相邻的点 有向 走到不能走停止 求停止时每一个点的期望 思路:写出方程消元 方 ...

  4. python的类型

    弱类型是可以自由转换的,如js,字符串和数字能相加 强类型不能自由转换,如python,要加上函数转成相同的类型

  5. LeetCode:最接近的三数之和【16】

    LeetCode:最接近的三数之和[16] 题目描述 给定一个包括 n 个整数的数组 nums 和 一个目标值 target.找出 nums 中的三个整数,使得它们的和与 target 最接近.返回这 ...

  6. IDEA:Application Server was not connected before run configuration stop, reason: Unable to ping 1099

    原文链接 : http://blog.csdn.net/x6582026/article/details/70807269 最近第一次玩IDEA时碰到tomcat启动问题:Application Se ...

  7. html5--1.3 元素的概念与3个常用标签

    html5--1.3 元素的概念与3个常用标签 学习要点 1.元素的概念 2.3个常用的标签 HTML 元素指的是从开始标签到结束标签的所有代码. 开始标签 元素内容 结束标签 <h1> ...

  8. 分享知识-快乐自己:SpringMvc整合遇到-前台传JSON参数,后台实体类对象接收

    前台数据转JSON对象: /** * * @param $myFrom:from表单 * @returns {{}} */ function from($myFrom) { var ebookEntr ...

  9. [原创]java操作word生成水印

    应用场景 为了保护版权或辨别文件的真伪,有时需要在生成的Word文件中动态添加水印,PageOffice组件的WaterMark类就封装了给在线编辑的Word文件添加水印这一功能,调用接口非常简单. ...

  10. [原创]Java动态生成word文档(图文并茂)

    很多情况下,软件开发者需要从数据库读取数据,然后将数据动态填充到手工预先准备好的Word模板文档里,这对于大批量生成拥有相同格式排版的正式文件非常有用,这个功能应用PageOffice的基本动态填充功 ...