维护一个支持翻转次数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


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

SGU 187.Twist and whirl - want to cheat( splay )的更多相关文章

  1. SGU 187 - Twist and whirl -- want to cheat

    原题地址:http://acm.sgu.ru/problem.php?contest=0&problem=187 太开心啦!!!!这道题从2013年开始困扰我!!今天晚上第四次下定决心把它写一 ...

  2. SGU题目总结

    SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...

  3. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  4. cheat sheet (小抄的意思-考试的时候,带在路上原先抄的重要的知识点)

    Cheat Sheet,这里面有个Cheat(欺骗),想当然的话,意思肯定不好.事实上,这Cheat Sheet 的原意的确也就是“小抄”的意思.所以,字典的定义是:“A piece of paper ...

  5. 转:PostgreSQL Cheat Sheet

    PostgreSQL Cheat Sheet CREATE DATABASE CREATE DATABASE dbName; CREATE TABLE (with auto numbering int ...

  6. Git Cheat Sheet

    Merge Undo git merge with conflicts $ git merge --abort Archive $ git archive --format zip --output ...

  7. CSS3 Animation Cheat Sheet:实用的 CSS3 动画库

    CSS3 Animation Cheat Sheet 是一组预设的动画库,为您的 Web 项目添加各种很炫的动画.所有你需要做的是添加样式表到你的网站,为你想要添加动画效果的元素应用预制的 CSS 类 ...

  8. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  9. ce游戏内存修改器(Cheat Engine)

    ce修改器(Cheat Engine)一款专门修改内存修改编辑的游戏工具它包括16进制编辑,反汇编程序,内存查找工具新版6.1 版的CE与6.0 最大的区别就是添加了修改器制作工具,比之前 5.6.1 ...

随机推荐

  1. Unity 绘制多边形

    最近工程需要用到一个多边形用来查看角色属性,于是就研究了下Mesh用网格做了一个.遗憾的的 UGUI 渲染不了 3D 物体,然后又用了一段时间研究了下UGUI的网格绘制. 不过终于还是完成了,虽然有些 ...

  2. C#中关于DBNULL的处理方法

    从数据库中获取数据有些会是空值的,这时一不注意就会被坑了…… String.Concat(db.可能为DBNULL的值) 在这种情况下,如果是DBNULL,得到的会是""

  3. MySqL触发器以及常用转换函数注意事项

    1,触发器(http://www.cnblogs.com/zzwlovegfj/archive/2012/07/04/2576989.html)       1.MYSQL中触发器中不能对本表进行 i ...

  4. error1

     #include<stdio.h>main(){ int a[10],i,m,n,j;   for(i=3;i<10;i++)    scanf("%d",&a ...

  5. HTML5 标签元素的一些注意事项

    不运行写结束标记的元素(但标签元素): area.base.br.col.command.embed.hr.img.input.keygen.link.meta.param.source.track. ...

  6. jmake 编译当前目录所有c/c++单文件

    在一个目录下写一些单文件的c或者c++文件时,每次敲出命令如g++ a.cpp -o a感觉比较麻烦. 所以就模仿makefile的功能,实现了扫描当前目录,并将所有c文件.cc文件.cpp文件直接调 ...

  7. 原版Windows XP Pro With SP3 VOL MSDN简体中文专业版

    2008年5月2日,微软推出Windows XP Pro With SP3 VOL MSDN x86 32位简体中文专业版,这是最经典也是我最喜爱的操作系统之一.在MSDN(微软开发者网络)的网站上查 ...

  8. (8) Xamarin使用Jar檔

    原文 Xamarin使用Jar檔 这个范例是如何在Xamarin.Android中去使用一个我们自行在开发的JAR档案. 主要会执行的步骤如下 在Xamarin建立一个Android Java Bin ...

  9. Android学习笔记:利用httpclient和AsyncTask 发起网络http post操作

    1.在android4中,发起网络http操作,不能在Activity的事件(即主线程)中进行,必须在单独的线程中操作. 另外进行网络操作,需要在manifest文件中增加如下的权限: <use ...

  10. hdu4288 Coder

    Coder Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...