Description

传送门

Solution

直接splay搞定吧。。似乎非旋treap也ok?

我已经菜到模板题都写不出来了qaq

Code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int n,m,A[];
struct Splay
{
int rt,cnt=;
int ch[][],num[][],sz[],fa[];
void pushup(int k){ sz[k]=sz[ch[k][]]+sz[ch[k][]]+num[k][]-num[k][]+;}
void build(int &k,int l,int r)
{
k=++cnt;
int mid=(l+r)/;
num[k][]=num[k][]=A[mid];
if (l<mid) build(ch[k][],l,mid-);
if (mid<r) build(ch[k][],mid+,r);
fa[ch[k][]]=fa[ch[k][]]=k;
pushup(k);
}
void rotate(int x,int &rt)
{
int y=fa[x],k=ch[y][]==x;
ch[y][k]=ch[x][k^];fa[ch[y][k]]=y;
if (y==rt) rt=x;else ch[fa[y]][ch[fa[y]][]==y]=x;
fa[x]=fa[y];
fa[y]=x;ch[x][k^]=y;
pushup(y);pushup(x);
}
void splay(int x,int &rt)
{
int y;
while (x!=rt)
{
y=fa[x];
if (y!=rt&&(ch[fa[y]][]==y)==(ch[y][]==x)) rotate(y,rt);
rotate(x,rt);
}
}
int work(int x,int k)
{
if (sz[ch[x][]]>=k) return work(ch[x][],k);
if (sz[x]-sz[ch[x][]]<k) return work(ch[x][],k-sz[x]+sz[ch[x][]]);
k-=sz[ch[x][]];int son;
if (k!=)
{
son=++cnt;
num[son][]=num[x][];num[son][]=num[son][]+k-;
num[x][]=num[son][]+; fa[son]=x;
ch[son][]=ch[x][];
ch[x][]=son;
pushup(son);
k=;
}
if (k!=num[x][]-num[x][]+)
{
son=++cnt;
num[son][]=num[x][]+k;
num[son][]=num[x][];
num[x][]=num[son][]-; fa[son]=x;
ch[son][]=ch[x][];
ch[x][]=son;
pushup(son);
}
return x;
}
void insert(int p,int a,int b)
{
int x1=work(rt,p),x2=work(rt,p+);
splay(x1,rt);
splay(x2,ch[x1][]);
int son=++cnt;
num[son][]=a;num[son][]=b;fa[son]=x2;
ch[x2][]=son;
sz[son]=b-a+;
pushup(x2);
pushup(x1);
}
void remove(int a,int b)
{
int x1=work(rt,a-),x2=work(rt,b+);
splay(x1,rt);
splay(x2,ch[x1][]);
ch[x2][]=;
pushup(x2);
pushup(x1);
}
int query(int x,int q)
{
if (!x) return ;
if (sz[ch[x][]]>=q) return query(ch[x][],q);
if (sz[x]-sz[ch[x][]]>=q)
{q-=sz[ch[x][]];return num[x][]+q-;}
return query(ch[x][],q-sz[x]+sz[ch[x][]]); }
}splay;
int _type,p,a,b;
int main()
{
scanf("%d%d",&n,&m);
n++;
for (int i=;i<=n;i++) scanf("%d",&A[i]);
n++;
splay.build(splay.rt,,n);
for (int i=;i<=m;i++)
{
scanf("%d",&_type);
if (!_type)
{
scanf("%d%d%d",&p,&a,&b);p++;
splay.insert(p,a,b);
}
if (_type==)
{
scanf("%d%d",&a,&b);a++;b++;
splay.remove(a,b);
}
if (_type==)
{
scanf("%d",&p);p++;
printf("%d\n",splay.query(splay.rt,p));
}
}
}

[BZOJ3678]wangxz与OJ-[Splay一类的平衡树]的更多相关文章

  1. 【BZOJ3678】wangxz与OJ Splay

    [BZOJ3678]wangxz与OJ Description 某天,wangxz神犇来到了一个信息学在线评测系统(Online Judge).由于他是一位哲♂学的神犇,所以他不打算做题.他发现这些题 ...

  2. BZOJ3678 wangxz与OJ (平衡树 无旋treap)

    题面 维护一个序列,支持以下操作: 1.在某个位置插入一段值连续的数. 2.删除在当前序列位置连续的一段数. 3.查询某个位置的数是多少. 题解 显然平衡树,一个点维护一段值连续的数,如果插入或者删除 ...

  3. BZOJ3678: wangxz与OJ

    splay缩点. #include<bits/stdc++.h> #define L(t) (t)->c[0] #define R(t) (t)->c[1] #define F ...

  4. bzoj 3678 wangxz与OJ

    3678: wangxz与OJ Time Limit: 10 Sec  Memory Limit: 128 MBhttp://www.lydsy.com/JudgeOnline/problem.php ...

  5. 洛谷P3285 [SCOI2014]方伯伯的OJ 动态开点平衡树

    洛谷P3285 [SCOI2014]方伯伯的OJ 动态开点平衡树 题目描述 方伯伯正在做他的 \(Oj\) .现在他在处理 \(Oj\) 上的用户排名问题. \(Oj\) 上注册了 \(n\) 个用户 ...

  6. 【bzoj3678】wangxz与OJ

    Portal -- > bzoj 3678 Solution 这题==真实智力康复qwq 然而众多神犇都说是10min写完的题我..可能写了近1h吧==深深感受到自己的弱小qwq (丢上来是因为 ...

  7. 【BZOJ3678】Wangxz和OJ

    题意: 不想讲 题解: Rope真香! 正解是Splay缩点,访问时再拆成一个序列 代码: //STL dafa good! #include<algorithm> #include< ...

  8. BZOJ 3595: [Scoi2014]方伯伯的Oj Splay + 动态裂点 + 卡常

    Description 方伯伯正在做他的Oj.现在他在处理Oj上的用户排名问题. Oj上注册了n个用户,编号为1-”,一开始他们按照编号排名.方伯伯会按照心情对这些用户做以下四种操作,修改用户的排名和 ...

  9. luogu P3285 [SCOI2014]方伯伯的OJ splay 线段树

    LINK:方伯伯的OJ 一道稍有质量的线段树题目.不写LCT splay这辈子是不会单独写的 真的! 喜闻乐见的是 题目迷惑选手 \(op==1\) 查改用户在序列中的位置 题目压根没说位置啊 只有排 ...

随机推荐

  1. antlr-2.7.6.jar的作用

    项目中没有添加antlr-2.7.6.jar,hibernate不会执行hql语句 并且会报NoClassDefFoundError: antlr/ANTLRException错误

  2. hdu-3397 Sequence operation 线段树多种标记

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3397 题目大意: 0 a b表示a-b区间置为0 1 a b表示a-b区间置为1 2 a b表示a- ...

  3. Extjs自定义验证介绍

    表单验证实例(空验证,密码确认验证,email验证) 我们可以用单独的js写表单验证,但是extjs已经为我们想到了(自己单独写反而不方便). 在验证之前,我不得不提两个小知识点: //大家在很多的e ...

  4. Java50道经典习题-程序34 三个数排序

    题目:输入3个数a,b,c,按大小顺序输出. import java.util.Scanner; public class Prog34 { public static void main(Strin ...

  5. VC++ TCP网络控制台程序

    在Windows7系统下,采用工具为VS2008,Win32控制台应用程序,编写一个基于TCP的Client/Server网络程序. 1.服务器端代码 #include <WinSock2.h& ...

  6. Vue 子组件调用父组件 $emit

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">      ...

  7. 《移动App测试实战》读书笔记

    第一章 概述 什么是移动产品? 移动产品是一个可以在移动设备上安装的App,或者一个可以在移动设备上访问的定制页面. 1.1 研发流程 互联网产品的研发过程主要涉及以下职位分工. 产品经理:负责产品方 ...

  8. 小程序的get和post需要注意的地方

    在进行异步请求之前先去小程序后台配置好服务器域名. get请求:header: { 'content-type':'json'}就可以. post请求:header: { 'content-type' ...

  9. 安装Win7时删除系统保留的100M隐藏分区

    原创文章,作者:lenbs,如若转载,请注明出处:https://www.smbinn.com/delwindows7100m.html 安装windows7新建磁盘分区时系统会自动创建100M的保留 ...

  10. Springboot 启动文件报错,原因是@ComponentScan写成了@ComponentScans

    Springboot 启动文件报错,原因是@ComponentScan写成了@ComponentScans