维护一个支持翻转次数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. FPGA开发(3)

    转载 榨干FPGA片上存储资源 记得Long long time ago,特权同学写过一篇简短的博文<M4K使用率>,文章中提到了Cyclone器件的内嵌存储块M4K的配置问题.文中提到了 ...

  2. Spring-----多环境中加载资源配置文件

    转载自:http://blog.csdn.net/hekewangzi/article/details/51942128

  3. zendStudio常用快捷键整理

    在来一发zendstudio的常用快捷键整理,今天心情不错哈哈 Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行Ctrl+Alt+↓ 复制当前行到下一行(复制增加)Ct ...

  4. JAVA日期字符串转化,日期加减

    SimpleDateFormat函数语法:  G 年代标志符  y 年  M 月  d 日  h 时 在上午或下午 (1~12)  H 时 在一天中 (0~23)  m 分  s 秒  S 毫秒  E ...

  5. CentOS yum安装配置lnmp服务器(Nginx+PHP+MySQL)

    1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport  ...

  6. RapidMiner的基本使用(一个医疗数据的简单决策树算法分析)

    RapidMiner的基本使用(一个医疗数据的简单决策树算法分析) RapidMiner的基本使用(一个医疗数据的简单决策树算法分析) 需要分析的文件: 右键分别创建读取excel数据,选择属性,设置 ...

  7. MSI文件静默安装

    以.net4为例,以下命令为静默安装: dotNetFx40_Full_x86_x64.exe /q /norestart /ChainingPackage FullX64Bootstrapper / ...

  8. [LeetCode]题解(python):151-Reverse Words in a String

    题目来源: https://leetcode.com/problems/reverse-words-in-a-string/ 题意分析: 给定一个字符串,里面包括多个单词,将这个字符串的单词翻转,例如 ...

  9. Werkzeug源码阅读笔记(四)

    今天主要讲一下werkzeug中的routing模块.这个模块是werkzeug中的重点模块,Flask中的路由相关的操作使用的都是这个模块 routing模块的用法 在讲解模块的源码之前,先讲讲这个 ...

  10. 使用MySQL处理百万级以上数据时,不得不知道的几个常识

    最近一段时间参与的项目要操作百万级数据量的数据,普通SQL查询效率呈直线下降,而且如果where中的查询条件较多时,其查询速度简直无法容忍.之前数据量小的时候,查询语句的好坏不会对执行时间有什么明显的 ...