牛客网暑期ACM多校训练营(第三场)C-Shuffle Cards

C++官方自带可持久化平衡树rope的3000行源码 C++官方rope3000行源码 // SGI's rope class -*- C++ -*- // Copyright (C) 2001-2015 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms o 阅读详情

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

题目描述

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 pi, si indicating that Eddy takes pi-th card from top to (pi+si-1)-th card from top(indexed from 1) and put them on the top of rest cards.


1 ≤ N, M ≤ 105
1 ≤ pi ≤ N
1 ≤ si ≤ N-pi+1

输出描述:

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

示例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大发好啊!请自行搜索 可持久化平衡树。

代码:

#include<iostream>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
int main()
{
    int n,m;
    while(cin>>n>>m){
        rope<int> r;
        for(int i=1;i<=n;i++){
            r.push_back(i);
        }
        int a,b;
        for(int i=0;i<m;i++){
            cin>>a>>b;
            r=r.substr(a-1,b)+r.substr(0,a-1)+r.substr(a+b-1,n-(a+b-1)+1);
        }
        for(int i=0;i<n;i++){
            cout<<r[i]<<" ";
        }
        cout<<endl;
    }
}

 

c++自带的可持久化平衡树?rope大法好!(超详细解答 + 5道例题讲解,可直接替代可持久化的线段树、并查集、平衡树!) c++自带的可持久化平衡树?rope大法好! C++官方说明 C++11及以后开始支持 可以当作可持久化平衡树使用,内部构造是一个块状链表 1. 声明 1)头文件 #include<ext/rope> 2)调用命名空间 using namespace __gnu_cxx; 3)声明使用 rope<int>Irp; rope<long long>Lrp; crope crp;//相当于定义成rope<char>,即定义为string类型 rope&lt 阅读详情

相关推荐

华三模拟器实战:3分钟搞定路由器DHCP地址池配置(附常见错误排查)

本文提供华三模拟器中路由器DHCP地址池的实战配置指南。通过分步详解,帮助用户在3分钟内完成基础设置,并深入讲解多地址池、中继配置等进阶应用。文章重点剖析了DHCP服务无法工作的常见原因,提供从客户端到服务器的系统性排错方法,助力快速定位并解决地址分配失败、获取参数错误等典型问题。

w1x2y3的博客 366

rope

链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网   题目描述 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 th...

xiaozheng的博客 562

手把手教你用Microsoft AEC Challenge数据集训练自己的回声消除模型(附完整代码)

本文详细介绍了如何使用Microsoft AEC Challenge数据集训练专业的回声消除模型,包括环境准备、数据清洗、模型架构设计、训练流程和实际部署注意事项。通过完整的代码示例和实战指南,帮助开发者快速掌握AEC技术,提升语音通信系统的回声消除效果。

weixin_27697385的博客 461

Rope大法(可持久化平衡树)

2008年OI集训论文上有介绍<对块状链表的一点研究>,其主要是结合了链表和数组各自的优点,链表中的节点指向每个数据 块,即数组,并且记录数据的个数,然后分块查找和插入。 头文件:#include <ext/rope> 命名空间:using namespace __gnu_cxx 基本操作: rope test; test.pu...

weixin_30689307的博客 677

开源AI数字人DUIX:从零构建你的智能交互助手

本文详细介绍了如何利用开源AI数字人DUIX从零构建智能交互助手。文章阐述了DUIX作为开源项目的核心优势,包括低成本启动、低网络依赖和高度可定制性,并提供了从开发环境搭建、核心模块(AI模型、语音、形象)配置到个性化业务逻辑开发与最终部署的完整实践指南,帮助开发者快速掌握构建专属AI数字人的全流程。

weixin_29051811的博客 508

编程助手:CLAUDE.md 与 AGENTS.md 完全指南

AI编程助手配置文件指南 为解决AI编程助手在陌生项目中面临的运行、规范、架构等问题,本文提出两种配置文件: CLAUDE.md(根目录): 面向通用AI(如ClaudeCode) 包含项目命令、代码风格、架构说明等结构化信息 示例:启动命令:npm run dev,代码规范:TypeScript禁用any AGENTS.md(任意目录): 面向智能编码工具(如Cursor) 支持模块级配置(如微前端子应用) 示例:前端测试命令:npm test:web,API请求规范 与传统README.md的区别: 人

分享AI、区块链技术及应用,未来已来 1272

(可持久化无旋Treap / stl)

1、利用可持久化无旋Treap 2、利用c++的stl容器crope,内部是用平衡树实现的,操作都是O(logN) 这里直接转了别人的代码 代码出处传送门 #include<iostream> #include<cstdio> #include<ext/rope> #include<string> using namespace std; using namespace __gnu_cxx; const int maxn=50005; crope ro,

CUCUC1的博客 508

【报错】open /var/lib/docker/tmp/docker-import-863402796/bin/json: no such file or directory

然后,通过docker images可以看到镜像已经加载进来了。然后,通过docker images可以看到镜像已经加载进来了。

静谧、淡雅 6238

牛客网暑期ACM多校训练营(第三场)C Shuffle Cards【Splay】

https://www.nowcoder.com/acm/contest/141/C 相邻区间的交换可以通过三次区间反转实现。 而区间反转可以通过Splay高效实现。 #include &lt;cstdio&gt; #include &lt;iostream&gt; #define il inline #define lson l,mid-1,now #define rson mid+1,r...

Irish_Moonshine的博客 562

Python与ArcGIS系列(二)获取地图文档

在ArcPy中,要引用当前的地图文档(Map Document),可以使用 mapping 模块中的 MapDocument 类。值得注意的是,在arcgis内部python窗口运行该代码才能访问已加载进arcgis的文档,如果通过其他idle则无法访问。要引用磁盘上的地图文档并对其进行一些设置,同样可以使用ArcPy中的 mapping 模块和 MapDocument 类。对于我们平常的工作,接触最多的就是图层数据处理,获取图层后就可以方便地进行下一步处理。

weixin_43894929的博客 2203

管理类联考——逻辑——真题篇——按知识分类——综合推理

29、某部门抽检了肉制品、白酒、乳制品、干果、蔬菜、水产品、饮料等﹖类商品共521种样品,发现其中合格样品515种,不合格样品6种。已知: (1)蔬菜、白酒中有2种不合格样品。 (2)肉制品、白酒、蔬菜、水产品中有5种不合格样品。 (3)蔬菜、乳制品、干果中有3种不合格样品。 根据上述信息,可以得出以下哪项? A. 乳制品中没有不合格样品。 B. 肉制品中没有不合格样品。 C. 蔬菜中没有不合格样品。 D. 白酒中没有不合格样品。 E. 水产品中没有不合格样品。 31~32题基于以下题干: 某中学举行田径运

stqer的博客 2049

牛客网暑期ACM多校训练营(第三场) C Shuffle Cards

题目:点击打开链接 题意:M个操作,每个操作都是从p开始的s个数移动到开头,问你最后的序列是什么。 分析:treap(树堆)或者Splay(伸展树)或者SBT(节点大小平衡树)都能实现,最方便的是利用STL中的rope,rope的底层实现是可持久化平衡树,复杂度为O(M*sqrt(N))。 代码: #pragma comment(linker, "/STACK:102400000,1024...

常胜将军的博客 274

4、接收天线:接收电压、功率和传输系数

本文详细探讨了接收天线的性能参数,包括接收电压、功率和传输系数,通过建立等效电路模型分析接收偶极子的电流和开路电压,并定义电压和功率传输函数。研究揭示了天线长度、工作频率及极化失配对传输性能的影响,并提出了优化接收天线性能的策略,为天线系统的设计与优化提供了理论支持。

ll5678的博客 240

牛客网暑期ACM多校训练营(第三场)C Shuffle Cards 题解(rope (可持久化平衡树)的使用)

Shuffle Cards 时间限制: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 ...

qq_41668093的博客 491

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

牛客网暑期ACM多校训练营(第三场): C. Shuffle Cards(splay)

链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网   题目描述 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 th...

加载中... 396

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

牛客网暑期ACM多校训练营(第三场)C(Shuffle Cards)

题目描述  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 randomnes...

snayf的博客 486

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

牛客网暑期ACM多校训练营(第三场) C Shuffle Cards (SPLAY)

这个题就是每次把一段区间移动到区间的最前面,问你若干次操作后的序列 按照题解说,这个题就是一个平衡树的操作题,之前没有做过平衡树的题,但是移动区间的时候想到了连续的翻转操作可以使得区间移动,所以,然后找了一个splay区间翻转的板子过了这个题,赛后发现stl 中有十分简单的工具可以实现。 看来要学习的东西还有很多 #include&amp;lt;stdio.h&amp;gt; #include&amp;lt;a...

beckyUp的博客 271

牛客网暑期ACM多校训练营(第三场)C Shuffle Cards(splay)

题目:点击打开链接 题意:将1~n的数进行m次操作,每次操作将第pi位到pi+si-1位的数字移到第一位,求最后的排列。 分析:splay区间翻转,相邻区间的交换可以通过三次区间反转实现。 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #pragma comment(linker, ...

常胜将军的博客 230

牛客网暑期ACM多校训练营(第三场)2018 C , Shuffle Cards ( rope )

题目描述 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 randomne...

Acer12138的博客 366

牛客网暑期ACM多校训练营(第三场)C.Shuffle Cards 平衡二叉树(无旋treap)

链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网   Shuffle Cards 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K Special Judge, 64bit IO Format: %lld 题目描述 Eddy likes to play cards game ...

xiuya19的博客 325

牛客网暑期ACM多校训练营(第三场) C Shuffle Cards 平衡树 rope的运用

链接:https://www.nowcoder.com/acm/contest/141/C来源:牛客网 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...

weixin_34241036的博客 221

牛客网暑期ACM多校训练营(第三场) C Shuffle Cards (Splay伸展树,rope 可持续化平衡树)

链接 链接: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 ...

henuzxy 482

牛客网暑期ACM多校训练营(第三场)C Shuffle Cards (STL rope)

题目大意:给出n个元素的序列,a[1]...a[n]. 接下来有操作,将从第p个开始s个元素拿出来放到开头。问经过若干次操作之后的序列是? rope参考链接:https://blog.csdn.net/qq_35649707/article/details/78828560 简单介绍rope: 类似指针链表的操作,时间复杂度会在n*(n^0.5),可以在很短的时间内实现快速的插入、删...

weixin_30726161的博客 112

牛客网暑期ACM多校训练营(第三场)C Shuffle Cards (rope 函数的简单使用)

题目大意:给出n个元素的序列,a[1]...a[n]. 接下来有操作,将从第p个开始s个元素拿出来放到开头。问经过若干次操作之后的序列是? 比如序列1,2,3,4,5.经过一次操作p=2,s=2,之后,序列变为2,3,1,4,5. 题目思路:使用STL的rope函数。一个很神奇的东西,STL中可持久化平衡树,可以解决一些简单的额Splay问题。 简单介绍rope: 类似指针链表的操作,时...

qq_36782366的博客 315

牛客网暑期ACM多校训练营(第三场) 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 al...

gtuif的博客 241
上一篇: UVA - 1354 Mobile Computing【这是我写过最认真的题解】 C++
下一篇: 牛客网暑期ACM多校训练营(第四场)D-Another Distinct Values
Zero_979
博客等级 码龄9年 124粉丝 331原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值