牛客多校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 题意 给出一个公式,求值 思路 明显的化简公式题,公式是分母连乘形式,这个时候要想到拆分,那如何拆分母呢,自然是裂项,此时有很多项裂项,我们不妨从 ...
随机推荐
- python数据分析之Pandas:基本功能介绍
Pandas有两个主要的数据结构:Series和DataFrame. Series是一种类似于一维数组的对象,它由一组数据以及一组与之相关的数据标签构成.来看下它的使用过程 In [1]: from ...
- 如何在MySQL中分配innodb_buffer_pool_size
如何在MySQL中分配innodb_buffer_pool_size innodb_buffer_pool_size是整个MySQL服务器最重要的变量. 1. 为什么需要innodb buffer p ...
- nvl()与regexp_replace()
NVL(字段,0):将空值转化为0 regexp_replace(字段, ‘[1-9]‘ ,'') is not null; 将数字转化为0
- 《程序员代码面试指南》第七章 位运算 在其他数都出现k 次的数组中找到只出现一次的数
题目 在其他数都出现k 次的数组中找到只出现一次的数 java 代码 package com.lizhouwei.chapter7; /** * @Description: 在其他数都出现k 次的数组 ...
- Android NDK环境搭建
本文主要记录NDK环境在Ubuntu下的搭建. 下载NDK 在官网进行下载NDK https://developer.android.com/ndk/downloads/index.html 当前最新 ...
- 20145239杜文超 《Java程序设计》第2周学习总结
20145239 <Java程序设计>第2周学习总结 教材学习内容总结 第三章主要介绍了Java语言的基础语法. 要求我们认识类型与变量,学习运算符的基本使用以及了解类型转换.运用基本流程 ...
- hihocoder 微软编程之美2015 初赛 第一场 (树算法 + 暴力思想 + 搜索思想)
题目1 : 彩色的树 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定一棵n个节点的树,节点编号为1, 2, …, n.树中有n - 1条边,任意两个节点间恰好有一条路 ...
- Spring Boot2.0之统一处理web请求日志
试问,你的项目中,如果有几万个方法,你还这么写log.info("name"+name+",age"+age )日志么?low~ 所以用AOP呀 1.首先创建个 ...
- 打造vim成类source insight
一.Ubuntu14.04下配置 1.配置vimrc文件 输入:version课查看vimrc文件及位置: system vimrc file: "$VIM/vimrc" user ...
- 如何去掉ArrayList重复的id
今天,也同样跟你一样寻找这个问题的解决办法, 如何去掉ArrayList重复的id 百度中找到这么一句话,为什么想到要去掉呢?为什么不反过来想,我在往ArrayList里添加的时候不让重复的项加入呢? ...