维护一个支持翻转次数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. Yii国际化

    Yii版本:1.1.13 1.将CMessageSource的$forceTranslation属性改为true Yii::app()->messages->forceTranslatio ...

  2. 依赖注入及AOP简述(十三)——AOP应用举例(完结) .

    2.     AOP应用举例 在一般的应用程序开发中,有一些典型的AOP应用,使得开发者可以专注于业务逻辑本身,而不是与之完全无关的一些“方面”. l        首先就是关于前面介绍过的日志输出类 ...

  3. vertical-align:middle的居中细节调整

    使用vertical-align:middle可以让行级元素垂直居中,但这个居中是以文字的中线来计算的,而文字的中线在不同的字体上不同,甚至相同的字体在不同的浏览器上显示的都不同.所以直接使用vert ...

  4. 使用CSS来显示XML

    实现效果学号 姓名 班级 课程 教师 表格背景设为绿色,单元格居中显示 学号部分,蓝色字体,16磅大小: 姓名部分红色字体,带有下划线,12磅大小 班级课程名,教师,绿色字体,12磅大小 XML代码: ...

  5. How to Send an Email Using UTL_SMTP with Authenticated Mail Server. (文档 ID 885522.1)

    APPLIES TO: PL/SQL - Version 9.2.0.1 to 12.1.0.1 [Release 9.2 to 12.1]Information in this document a ...

  6. 介绍Foundation框架

    开始介绍Foundation框架.OC中的Foundation框架是系统提供了,他就相当于是系统的一套api,和Java中的一些系统jar很相似,又早起的一批人开发的,内部有很多现有的类和功能提供给我 ...

  7. oracle ORA-00913: 值过多

    --oracle中查看表是否被锁 查看表是否被锁   SELECT /*+ rule*/   a.sid, b.owner, object_name, object_type   FROM v$loc ...

  8. 【codevs】2776寻找代表元

    题目描述 Description 广州二中苏元实验学校一共有n个社团,分别用1到n编号.广州二中苏元实验学校一共有m个人,分别用1到m编号.每个人可以参加一个或多个社团,也可以不参加任何社团.每个社团 ...

  9. leetcode Linked List Cycle II python

    # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = ...

  10. HTML豆ちしき

    HTML文档里所有的空白符(空格,Tab,换行,回车)会被浏览器忽略,唯一的例外是空格,对空格的处理方式是所有连续的空格被当成一个空格,不管有一个,还是两个,还是100个.之所以有这样的规则是因为忽略 ...