牛客多校3 C-Shuffle Cards(rope大法解决数组分块)
Shuffle Cards
链接:https://www.nowcoder.com/acm/contest/141/C
来源:牛客网
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld
题目描述
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
-->
输出
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大法解决数组分块)的更多相关文章
- 牛客多校第3场 J 思维+树状数组+二分
牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...
- 2019牛客多校第一场 I Points Division(动态规划+线段树)
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
- 牛客多校第一场 B Inergratiion
牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...
- 2019牛客多校第二场 A Eddy Walker(概率推公式)
2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...
- 牛客多校第三场 F Planting Trees
牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...
- 牛客多校第三场 G Removing Stones(分治+线段树)
牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...
- 牛客多校第四场sequence C (线段树+单调栈)
牛客多校第四场sequence C (线段树+单调栈) 传送门:https://ac.nowcoder.com/acm/contest/884/C 题意: 求一个$\max {1 \leq l \le ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
- 2019年牛客多校第一场B题Integration 数学
2019年牛客多校第一场B题 Integration 题意 给出一个公式,求值 思路 明显的化简公式题,公式是分母连乘形式,这个时候要想到拆分,那如何拆分母呢,自然是裂项,此时有很多项裂项,我们不妨从 ...
随机推荐
- pycharm注册码地址
(1)地址:http://idea.lanyus.com/ (2)注意,在破解的时候,是先修改hosts文件所在路径:“C:\Windows\System32\drivers\etc\hosts”,修 ...
- wx.onNetworkStatusChange(function (res) 监听网络状态变化 实践方案
网络状态 · 小程序 https://developers.weixin.qq.com/miniprogram/dev/api/device.html#wxonnetworkstatuschangec ...
- Refused to set unsafe header
Refused to set unsafe header Refused to set unsafe header "Host"waitServerDeal @ tGet.html ...
- 【题解】P1613跑路
[题解]P1613 鸽王跑路 一道思维好题! 考虑\(2^k\)的传递性.直接64遍\(floyd\)求所有\(2^k\)的路径,转移方程是 \(dp(i,j,k)=[dp[i][t][k-1]\)& ...
- HNOI2016
本蒟蒻表示终于$AC$了$HNOI2016$的六道毒瘤题... 高兴! 附上各个题的题解: $DAY1$: $T1$: BZOJ4537: [Hnoi2016]最小公倍数 $T2$: BZOJ4538 ...
- ubuntu在vim里搜索关键字
在命令模式下敲斜杆( / )这时在状态栏(也就是屏幕左下脚)就出现了 “/” 然后输入你要查找的关键字敲回车就可以了. 如果你要继续查找此关键字,敲字符 n 就可以继续查找了.
- luoguP3066 [USACO12DEC]逃跑的BarnRunning
luoguP3066 [USACO12DEC]逃跑的BarnRunning 题目大意 给定一棵n个节点的树和参数L,查询每个节点子树中到达该节点距离<=L的数量(包括该节点) 偏模板的主席树 P ...
- Python爬虫 —— 抓取美女图片(Scrapy篇)
杂谈: 之前用requests模块爬取了美女图片,今天用scrapy框架实现了一遍. (图片尺度确实大了点,但老衲早已无恋红尘,权当观赏哈哈哈) Item: # -*- coding: utf-8 - ...
- C++之封装
希望暴露public 希望隐藏private 对象实例化有两种方式,从栈实例化,从堆(new出来的)实例化. 以谁做什么作为核心. public 放前面,private放后面(属性可以定义为priva ...
- DOM (文档对象模型(Document Object Model)
DOM(文档对象模型(Document Object Model) 文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言的标准编程接口.在网页上 ...