Description

 

您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2 3 4 1

Input

第一行为n,m n表示初始序列有n个数,这个序列依次是(1,2……n-1,n)  m表示翻转操作次数
接下来m行每行两个数[l,r] 数据保证 1<=l<=r<=n

Output

输出一行n个数字,表示原始序列经过m次变换后的结果

Sample Input

5 3

1 3

1 3

1 4

Sample Output

4 3 2 1 5

HINT

N,M<=100000

Source

splay区间操作大裸题不解释。

 #include<queue>
#include<cstdio>
#include<cstdlib>
using namespace std; #define maxn 100010
const int inf = << ;
queue <int> team;
struct TREE
{
int ch[maxn][],fa[maxn],cnt,root;
int key[maxn],size[maxn],t[maxn]; inline int newnode()
{
if (team.empty()) return ++cnt;
int ret = team.front(); team.pop();
return ret;
} inline TREE()
{
root = newnode();
key[root] = -inf; ++t[root];
updata(root);
add(inf);
} inline int find(int rank,int have,int now)
{
if (have+size[ch[now][]]<rank&&have+size[ch[now][]]+t[now]>=rank) return now;
if (have+size[ch[now][]]+t[now]<rank) return find(rank,have+size[ch[now][]]+t[now],ch[now][]);
else return find(rank,have,ch[now][]);
} inline void updata(int now) { size[now] = size[ch[now][]] + size[ch[now][]] + t[now]; } inline void rotate(int x)
{
int y = fa[x],z = fa[y],l = ch[y][] != x,r = l ^ ;
if (z != ) ch[z][ch[z][] != y] = x;
fa[x] = z; fa[y] = x; fa[ch[x][r]] = y;
ch[y][l] = ch[x][r]; ch[x][r] = y;
updata(y); updata(x);
} inline void splay(int x,int aim)
{
int p = fa[aim];
while (fa[x] != p)
{
int y = fa[x],z = fa[y];
if (z != p)
{
if ((ch[z][] == y)^(ch[y][] == x)) rotate(x);
else rotate(y);
}
rotate(x);
}
if (aim == root) root = x;
} inline int search(int x)
{
int now = root;
while (now)
{
if (key[now] == x) break;
now = ch[now][x > key[now]];
}
return now;
} inline void add(int x)
{
int now = root,pre = ;
while (now)
{
pre = now;
now = ch[now][x > key[now]];
}
now = newnode();
fa[now] = pre; ch[pre][x > key[pre]] = now;
key[now] = x; ++t[now];
pre = now;
while (now)
{
updata(now);
now = fa[now];
}
splay(pre,root);
} inline int qrank(int x)
{
int now = root,ret = ;
while (key[now] != x)
{
if (x < key[now]) now = ch[now][];
else ret += size[ch[now][]] + t[now],now = ch[now][];
}
return ret + size[ch[now][]] + ;
} inline void insert(int x)
{
int p = search(x);
if (p)
{
splay(p,root);
++t[p];
updata(p);
}
else add(x);
} inline void del(int x)
{
int now = search(x),k = qrank(x);
int p = find(k-,,root),q = find(k + t[now],,root);
splay(p,root);
splay(q,ch[p][]);
if (--t[now])
{
updata(now);
updata(q);
updata(p);
}
else
{
ch[q][] = ; fa[now] = ;
updata(q);
updata(p);
team.push(now);
}
} inline int ask(int x,int sign)
{
int now = root,ret;
while (now)
{
if (sign)
{
if (key[now] > x)
ret = now,now = ch[now][];
else now = ch[now][];
}
else
{
if (key[now] < x)
ret = now,now = ch[now][];
else now = ch[now][];
}
}
return key[ret];
}
}tree; inline int read()
{
int x=,f=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} int main()
{
freopen("3224.in","r",stdin);
freopen("3224.out","w",stdout);
int T = read();
while (T--)
{
int opt = read();
if (opt == ) tree.insert(read());
else if (opt == ) tree.del(read());
else if (opt == ) printf("%d\n",tree.qrank(read())-);
else if (opt == ) printf("%d\n",tree.key[tree.find(read()+,,tree.root)]);
else if (opt == ) printf("%d\n",tree.ask(read(),));
else printf("%d\n",tree.ask(read(),));
}
fclose(stdin); fclose(stdout);
return ;
}

BZOJ 3223 文艺平衡树的更多相关文章

  1. [题解]bzoj 3223 文艺平衡树

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3884  Solved: 2235[Submit][Sta ...

  2. bzoj 3223 文艺平衡树 - Splay

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3884  Solved: 2235[Submit][Sta ...

  3. BZOJ 3223 文艺平衡树 [codevs3303翻转区间]

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=3223 通道2:http://codevs.cn/problem/3303/ 题目分析: 我 ...

  4. bzoj 3223 文艺平衡树 splay 区间翻转

    Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 17715  Solved: 7769[Submit][Status][ ...

  5. bzoj 3223 文艺平衡树 Splay 打标志

    是NOI2003Editor的一个子任务 #include <cstdio> #include <vector> #define maxn 100010 using names ...

  6. [bzoj3224]普通平衡树/3223文艺平衡树

    这是一道很普通的题.. 最近花了很多时间来想要去干什么,感觉自己还是太拿衣服 做这道题是因为偶尔看到了lavender的blog和她的bzoj早期AC记录,就被题目深深地吸引到了,原因有二: 自己sp ...

  7. 3223. 文艺平衡树【平衡树-splay】

    Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2 3  ...

  8. BZOJ 3223: Tyvj 1729 文艺平衡树

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3628  Solved: 2052[Submit][Sta ...

  9. BZOJ 3223: Tyvj 1729 文艺平衡树(splay)

    速度居然进前十了...第八... splay, 区间翻转,用一个类似线段树的lazy标记表示是否翻转 ------------------------------------------------- ...

随机推荐

  1. StrutsPrepareAndExecuteFilter(转)

    http://www.iteye.com/topic/829843  一.概述 Struts2的核心是一个Filter,Action可以脱离web容器,那么是什么让http请求和action关联在一起 ...

  2. C++一些注意点之操作符重载

    重载操作符需要注意 (1)重载操作符必须具有一个类类型操作数.不能重载内建类型的操作符. operator +(int,int);//这个是错误的,都为内建类型 operator +(int,clas ...

  3. SQL语法集锦三:合并列值与分拆列值

    本文转载http://www.cnblogs.com/lxblog/archive/2012/09/29/2708724.html 在SQL中分拆列值和合并列值老生常谈了,从网上搜刮了一下并记录下来, ...

  4. 使用jsdoc-toolkit来自动生成js api文档

    近来前端组小盆友开发的类库越来越多,很多情况下彼此不知道写了些什么方法,为了更好的合作提高工作效率,找了个比较好的api文档生成方法.使用jsdoc-toolkit来自动生成js api文档. 一.  ...

  5. Apache SSL服务器配置SSL详解(转)

    1.安装必要的软件 引用 我用的是apahce2.0.61版,可以直接官方提供的绑定openssl的apache. 文件名是:apache_2.0.61-win32-x86-openssl-0.9.7 ...

  6. 第二篇:从 GPU 的角度理解并行计算

    前言 本文从使用 GPU 编程技术的角度来了解计算中并行实现的方法思路. 并行计算中需要考虑的三个重要问题 1. 同步问题 在操作系统原理的相关课程中我们学习过进程间的死锁问题,以及由于资源共享带来的 ...

  7. [转] Initial Impressions on GraphQL & Relay

    https://kadira.io/blog/graphql/initial-impression-on-relay-and-graphql http://graphql.org/blog/subsc ...

  8. c++矩阵运算

    优化了一些算法 #pragma once #include <iostream> #include <iomanip> #include <string> #def ...

  9. GET和POST本质上有什么区别

    如果有人问你,GET和POST,有什么区别?你会如何回答? 我的经历 前几天有人问我这个问题.我说GET是用于获取数据的,POST,一般用于将数据发给服务器之用. 这个答案好像并不是他想要的.于是他继 ...

  10. 利用MutationObserver对页面元素的改变进行监听

    'use strict'; let MutationObserver = window.MutationObserver || window.WebKitMutationObserver || win ...