牛客网暑期ACM多校训练营(第三场) C Shuffle Cards 平衡树 rope的运用
链接:https://www.nowcoder.com/acm/contest/141/C
来源:牛客网
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 比赛的时候是模拟想到死,emmmmm,真的烦,一直没有做出来
比赛后看到别人用rope的代码
惊呆了
还是见识少了
这里补充下rope的知识
#include <ext/rope>
using namespace __gnu_cxx;
int a[1000];
rope<int> x;
rope<int> x(a,a + n);
rope<int> a(x); x->at(10);
x[10];
x->push_back(x) // 在末尾添加x
x->insert(pos,x) // 在pos插入x
x->erase(pos,x) // 从pos开始删除x个
x->replace(pos,x) // 从pos开始换成x
x->substr(pos,x) // 提取pos开始往后x个
rope的原理是平衡树
打算今晚做几个题目
贴一下AC代码
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <ext/rope>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
using namespace __gnu_cxx;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
typedef long long ll;
rope<ll> r;
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll n, m;
while( cin >> n >> m ) {
r.clear();
for( ll i = 1; i <= n; i ++ ) {
r.push_back(i);
}
ll a, b;
while( m -- ) {
cin >> a >> b;
r = r.substr(a-1,b) + r.substr(0,a-1) + r.substr(a+b-1,n-a-b+1);
}
for( ll i = 0; i < n-1; i ++ ) {
cout << r[i] << " ";
}
cout << r[n-1] << endl;
}
return 0;
}
牛客网暑期ACM多校训练营(第三场) C Shuffle Cards 平衡树 rope的运用的更多相关文章
- 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?
牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...
- 牛客网 暑期ACM多校训练营(第一场)A.Monotonic Matrix-矩阵转化为格子路径的非降路径计数,Lindström-Gessel-Viennot引理-组合数学
牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你 ...
- 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)
2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...
- 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)
链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...
- 牛客网暑期ACM多校训练营(第九场) A题 FWT
链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...
- 牛客网暑期ACM多校训练营(第九场)D
链接:https://www.nowcoder.com/acm/contest/147/D来源:牛客网 Niuniu likes traveling. Now he will travel on a ...
- 牛客网暑期ACM多校训练营(第二场)B discount
链接:https://www.nowcoder.com/acm/contest/140/B来源:牛客网 题目描述 White Rabbit wants to buy some drinks from ...
- 2018牛客网暑期ACM多校训练营(第一场)D图同构,J
链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...
- 牛客网暑期ACM多校训练营(第二场) I Car 思维
链接:https://www.nowcoder.com/acm/contest/140/I来源:牛客网 White Cloud has a square of n*n from (1,1) to (n ...
- 牛客网暑期ACM多校训练营(第二场) D money 思维
链接:https://www.nowcoder.com/acm/contest/140/D来源:牛客网 White Cloud has built n stores numbered from 1 t ...
随机推荐
- poj 2524 Ubiquitous Religions(简单并查集)
对与知道并查集的人来说这题太水了,裸的并查集,如果你要给别人讲述并查集可以使用这个题当做例题,代码中我使用了路径压缩,还是有一定优化作用的. #include <stdio.h> #inc ...
- 坐标下降法(coordinate descent method)求解LASSO的推导
坐标下降法(coordinate descent method)求解LASSO推导 LASSO在尖点是singular的,因此传统的梯度下降法.牛顿法等无法使用.常用的求解算法有最小角回归法.coor ...
- kubeadm定制化开发,延长证书
kubernetes离线安装包,仅需三步 修改kubeadm证书过期时间 本文通过修改kubeadm源码让kubeadm默认的一年证书过期时间修改为99年 我已经编译好了一个放在了github上,有需 ...
- Css3动画效果,彩色文字效果,超简单的loveHeart
<!DOCTYPE html><html><head><meta charset="utf-8" /><title>Cs ...
- Ant Design Pro 脚手架+umiJS 实践总结
一.简介 1.Ant Design Pro Ant Design Pro是一款搭建中后台管理控制台的脚手架 ,基于React,dva.js,Ant Design (1)其中dva主要是控制数据流向,是 ...
- (2019版本可用)【idea的安装,激活,设置,卸载】
前言 也差不多也可以使用简单快捷的idea软件了,相对于elicpse而言的话,idea是非常好用的,虽然现在涉及不是很广. 什么是idea? IDEA 全称IntelliJ IDEA,是用于java ...
- alpine 镜像 java 日志中文问号乱码
0x00 前言 吾使用 alpine 作为基础镜像构建了 jdk8 镜像,为线上业务的 java 微服务架构提供支持,但是有容器运行的 java 服务中打印的日志中一旦出现中文,就会出现诸如以下的 ? ...
- loging日志的使用
2.日志: 记住怎么使用就好了 自己定义日志开始 import logging logger = logging.getLogger() # 创建一个logger fh = logging.FileH ...
- Visual Studio 2015&2017 key
Visual Studio 2015 key Key : HMGNV-WCYXV-X7G9W-YCX63-B98R2 Visual Studio Enterprise 2015 Key :HM6NR- ...
- Zabbix监控华为路由器配置
zabbix监控华为路由器 一.配置路由器界面: 开启snmpv2c功能,同时勾选v2c版本(不要勾v1,不安全,其实v2也不安全,如果很注重安全的话,一定要只配置v3). 手里没有路由器登录账号,大 ...