SGU 187.Twist and whirl - want to cheat( splay )

维护一个支持翻转次数M的长度N的序列..最后输出序列.1<=N<=130000, 1<=M<=2000

splay裸题...

-------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 130009;
struct Node {
Node *p, *ch[2];
int s, v;
bool rev;
inline void setc(Node* t, int c) {
ch[c] = t;
t->p = this;
}
inline int d() {
return p->ch[1] == this;
}
inline void Rev() {
rev ^= 1;
}
inline void pushDown() {
if(rev) {
ch[0]->Rev();
ch[1]->Rev();
swap(ch[0], ch[1]);
rev = false;
}
}
inline void upd() {
s = ch[0]->s + ch[1]->s + 1;
}
} mempool[maxn], *pt, *Root, *Null;
void InitSplay() {
pt = mempool;
Root = Null = pt++;
Null->s = 0;
Null->setc(Null, 0);
Null->setc(Null, 1);
}
Node* newNode(int v) {
pt->v = v;
pt->rev = false;
pt->s = 1;
pt->p = pt->ch[0] = pt->ch[1] = Null;
return pt++;
}
void Rot(Node* t) {
Node* p = t->p;
p->pushDown();
t->pushDown();
int d = t->d();
p->p->setc(t, p->d());
p->setc(t->ch[d ^ 1], d);
t->setc(p, d ^ 1);
p->upd();
if(p == Root) Root = t;
}
void Splay(Node* t, Node* f = Null) {
for(Node* p = t->p; p != f; p = t->p) {
if(p->p != f)
p->d() != t->d() ? Rot(t) : Rot(p);
Rot(t);
}
t->upd();
}
Node* Build(int l, int r) {
if(l >= r) return Null;
int m = (l + r) >> 1;
Node* t = newNode(m);
t->setc(Build(l, m), 0);
t->setc(Build(m + 1, r), 1);
t->upd();
return t;
}
Node* Select(int k) {
for(Node* t = Root; ; ) {
t->pushDown();
int s = t->ch[0]->s;
if(k == s) return t;
if(k < s)
t = t->ch[0];
else
k -= s + 1, t = t->ch[1];
}
}
Node* Range(int l, int r) {
Splay(Select(--l));
Splay(Select(++r), Root);
return Root->ch[1]->ch[0];
}
void DFS(Node* t) {
if(t == Null) return;
t->pushDown();
DFS(t->ch[0]);
printf("%d ", t->v);
DFS(t->ch[1]);
}
int N, M;
int main() {
InitSplay();
scanf("%d%d", &N, &M);
Root = Build(0, N + 2);
while(M--) {
int l, r;
scanf("%d%d", &l, &r);
Node* t = Range(l, r);
t->Rev();
Splay(t);
}
DFS(Range(1, N));
return 0;
}

-------------------------------------------------------------

187. Twist and whirl - want to cheat

time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard input
output: standard output



A well-known sharper I*** invented a new way to swindle people. There are N thimbles on the table, and there is a small ball with the number under each of them. The balls are numbered with numbers from 1 to N from left to right. At one operation I*** changes the order of some subsequence of successive thimbles to the opposite. Your task is to find the order of numbers (from left to right) in sequence after all of his manipulations. The total number of manipulations is M.

Input
The first line contains two integer numbers N and M (1<=N<=130000, 1<=M<=2000) separated by a space. Each of the following M lines contains two integer numbers Pi, Qi (1<=Pi<=Qi<=N) - positions of the leftmost and rightmost thimbles in rotated sequence.

Output
Output the sequence of N numbers - the numbers of balls in the thimbles from left to right.

Sample test(s)

Input
Test #1 
5 2 
1 3 
4 5 

Test #2 
5 2 
1 4 
2 5 

Output
Test #1 
3 2 1 5 4 

Test #2 
4 5 1 2 3
[submit]
[forum]

Author:Michael R. Mirzayanov
Resource:ACM International Collegiate Programming Contest 2003-2004 
North-Eastern European Region, Southern Subregion
Date:2003 October, 9




 

转载于:https://www.cnblogs.com/JSZX11556/p/5049649.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/373955.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

练习一万小时成天才

随着畅销书《异类》的流行&#xff0c;“练习一万小时成天才”这个口号现在是尽人皆知。也许仍然有不少人相信那些不世出的天才必有天生的神秘能力&#xff0c;但科学家通过大量的调查研究已经达成共识&#xff0c;那就是所有顶级高手都是练出来的。不但如此&#xff0c;最近几…

(转)数据流图

转自:http://jingyan.baidu.com/article/4f34706eefdb04e387b56deb.html 数据流图4种图元 数据流图的实例 转载于:https://www.cnblogs.com/wrencai/p/5852389.html

从CLI监视OpenJDK

目前&#xff0c;我大部分时间在Java虚拟机 &#xff08;JVM&#xff09;内或周围进行大量工作&#xff0c;大部分时间是在Linux上。 当事情变得不对劲并且我试图确定原因时&#xff0c;我接触了Java性能分析工具。 这些工具有两种形式&#xff0c;一种是精美的GUI&#xff08;…

python数据库优化_python | Mysql性能优化一

对mysql优化是一个综合性的技术&#xff0c;主要包括表的设计合理化(符合3NF)添加适当索引(index) [四种: 普通索引、主键索引、唯一索引unique、全文索引]分表技术(水平分割、垂直分割)读写[写: update/delete/add]分离存储过程 [模块化编程&#xff0c;可以提高速度]对mysql配…

MySQL中文乱码问题

项目中用到MySQL数据库时中文出现乱码问题&#xff08;中文字符都变成了&#xff1f;&#xff09;解决&#xff1a; 1、统一项目与数据库的编码&#xff0c;项目中用的是UTF-8因此我的把数据库的编码统一成UTF-8 修改方式&#xff1a;修改 MySQL根目录中的 my.ini 文件替换d…

json与字符串互转

1 字符串转JSON var objeval((str"))var objJSON.parse(str)var objstr.parseJSON()2 JSON转字符串 var strobj.toJSONString()var strJSON.stringify(obj)转载于:https://www.cnblogs.com/liu-xia/p/5050878.html

使用RequestFactory API进行Spring GWT集成

从GWT 2.4开始&#xff0c;将RequestFactory API与后端的Spring服务集成很容易&#xff0c;您需要做的就是在服务器上创建一个自定义ServiceLocator&#xff0c;GWT将使用它来正确定位被调用的服务&#xff1a; public class SpringServiceLocator implements ServiceLocator {…

C++实例讲解Binder通信

binder是android里面的通信机制&#xff0c;这就不说它如何如何好了&#xff0c;Goog已经说过了&#xff0c;这里不多说。binder是一个面向对象的编程方法&#xff0c;大量使用虚函数类。最近研究binder看到一网友写的&#xff0c;就借鉴一下。这个例子很好的解释里binder通信关…

2014编程之美初赛第一场

题目1 : 焦距 时间限制:2000ms单点时限:1000ms内存限制:256MB描述 一般来说&#xff0c;我们采用针孔相机模型&#xff0c;也就是认为它用到的是小孔成像原理。 在相机坐标系下&#xff0c;一般来说&#xff0c;我们用到的单位长度&#xff0c;不是“米”这样的国际单位&#x…

高中python公开课怎么上好_如何上好高中英语公开课

谈如何上好高中英语公开课对青年教师来说&#xff0c;开一节公开课&#xff0c;如同完成一次蜕变&#xff0c;累掉一层皮&#xff0c;有着刻骨铭心的阵痛&#xff0c;但换来的是突飞猛进的专业成长。可以说&#xff0c;公开课是青年教师培训的有效途径&#xff0c;是名师培养的…

Codeforces Round #261 (Div. 2) - E (459E)

题目连接&#xff1a;http://codeforces.com/contest/459/problem/E 题目大意&#xff1a;给定一张有向图&#xff0c;无自环无重边&#xff0c;每条边有一个边权&#xff0c;求最长严格上升路径长度。(1≤n&#xff0c;m≤3 *10^5) 初见此题觉得以边为点&#xff0c;以点为边&…

回收对象以提高性能

总览 在上一篇文章中&#xff0c;我说过对象反序列化更快的原因是由于使用了回收对象。 由于两个原因&#xff0c;这可能令人惊讶&#xff1a;1&#xff09;相信如今创建对象是如此之快&#xff0c;无关紧要或与回收自己一样快&#xff0c;2&#xff09;默认情况下&#xff0c;…

jquery GET POST

<!DOCTYPE html> <html> <head> <meta charset"UTF-8"> <head> <!--引入百度库--> <script src"http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <title></title> <scrip…

C++高精度运算类bign (重载操作符)

大数据操作&#xff0c;有如下问题&#xff1a; 计算&#xff1a;45678913561232654213212314875231656511323132 456789135612326542132123*14875231656511323132 比较&#xff1a;7531479535511335666686565>753147953551451213356666865 ? long long类型存储不了&…

oj系统格式错误_论文查重会不会检查格式?【paperpp吧】

高等学校一般都会要求大学生在毕业时需要写作毕业论文&#xff0c;并且会提前发出关于毕业论文的通知&#xff0c;在通知上一般会说明论文写作的相关要求&#xff0c;其中就会规定论文的相关格式。当然&#xff0c;学校也会在通知中说明论文查重的相关事宜&#xff0c;那么论文…

JavaScript Cookies

相关&#xff1a;jquery-cookie cookie 是存储于访问者的计算机中的变量&#xff0c;常用来存储用户名字&#xff0c;密码&#xff0c;日期&#xff0e; 示例&#xff1a; 1 document.cookie"usernameJohn Doe"; 2 document.cookie"usernameJohn Doe; expiresTh…

大数据 -- Hadoop集群搭建

Hadoop集群搭建 1.修改/etc/hosts文件 在每台linux机器上&#xff0c;sudo vim /etc/hosts 编写hosts文件。将主机名和ip地址的映射填写进去。编辑完后&#xff0c;结果如下&#xff1a; 2.配置ssh&#xff0c;实现无密码登录 四台虚拟机上&#xff0c;使用&#xff1a; ssh-ke…

通过示例休眠–第2部分(DetachedCriteria)

所以上次我们帮助正义联盟有效地管理了他们的超级英雄。 今天&#xff0c;我们集中讨论“复仇者联盟”将如何使用冬眠的“分离标准”找出每个超级英雄的敌人&#xff0c;以保护他们的超级英雄。 您可以从此处下载工作示例。 在此示例中&#xff0c;我们仅考虑两个实体。 复仇者…

2014编程之美初赛第二场

题目1 : 神奇的数列 时间限制:2000ms单点时限:1000ms内存限制:256MB描述 大神同学是一个热爱数字的孩子&#xff0c;她无时无刻不在思考生活与数学的联系。有一天&#xff0c;她发现其实公历的设计是有讲究的。 每4年就会多闰一天&#xff0c;每一百年又会有一年不是闰年&#…

usb大容量存储设备驱动_usb无法识别怎么办 如何解决usb识别故障【详细步骤】...

usb无法识别怎么办? 随着计算机硬件飞速发展&#xff0c;外围设备日益增多&#xff0c;键盘、鼠标等早已为人所共知&#xff0c;数码相机、MP3随身听接踵而至&#xff0c;这么多的设备&#xff0c;如何接入个人计算机?USB就是基于这个目的产生的。USB是一个使计算机周边设备连…