BZOJ1895: Pku3580 supermemo
1895: Pku3580 supermemo
Time Limit: 15 Sec Memory Limit: 64 MB
Submit: 77 Solved: 47
[Submit][Status]
Description
1. ADDxyD:给子序列fAx:::Ayg的每个元素都加上D。例如对f1,2,
3,4,5g执行"ADD 241" 会得到f1,3,4,5,5g。
2. REVERSExy:将子序列fAx:::Ayg翻转。例如对f1,2,3,4,5g执
行"REVERSE 24"会得到f1,4,3,2,5g。
3. REVOLVExyT:将子序列fAx:::Ayg旋转T个单位。例如,
对f1,2,3,4,5g执行"REVOLVE 242"会得到f1,3,4,2,5g。
4. INSERTxP:在Ax后插入P。例如,对f1,2,3,4,5g执行"INSERT
24"会得到f1,2,4,3,4,5g。
5. DELETEx:删去Ax。例如,对f1,2,3,4,5g执行"DELETE 2"会得
到f1,3,4,5g。
6. MINxy:查询子序列fAx:::Ayg中的最小元素。例如,对于序列f1,
2,3,4,5g,询问"MIN 24"的返回应为2。
Input
以下n行每行包含一个整数,描述初始的序列。
接下来一行包含一个整数m,表示操作的数目。
以下m行每行描述一个操作。
Output
Sample Input
1
2
3
4
5
2
ADD 2 4 1
MIN 4 5
Sample Output
HINT
输入、输出以及中间运算结果均不会超过32位整数。
对于30%的数据,n;m 6 1000;
对于100%的数据,n;m 6 100000。
Source
题解:
又被输入坑了。。。
splay裸题。。。T了5.6次,最后把每次的字符串清空然后就A了。。。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 2000000+5
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
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 n,q,tot,fa[maxn],c[maxn][],rt,t1,t2,s[maxn],tag[maxn],mi[maxn],v[maxn];
bool rev[maxn];
inline void pushup(int x)
{
if(!x)return;
int l=c[x][],r=c[x][];
s[x]=s[l]+s[r]+;
mi[x]=min(v[x],min(mi[l],mi[r]));
}
inline void rotate(int x,int &k)
{
int y=fa[x],z=fa[y],l=c[y][]==x,r=l^;
if(y!=k)c[z][c[z][]==y]=x;else k=x;
fa[x]=z;fa[y]=x;fa[c[x][r]]=y;
c[y][l]=c[x][r];c[x][r]=y;
pushup(y);pushup(x);
}
inline void splay(int x,int &k)
{
while(x!=k)
{
int y=fa[x],z=fa[y];
if(y!=k)
{
if((c[z][]==y)^(c[y][]==x))rotate(x,k);else rotate(y,k);
}
rotate(x,k);
}
}
inline void add(int x,int z)
{
if(!x)return;
mi[x]+=z;tag[x]+=z;v[x]+=z;
}
inline void rever(int x)
{
if(!x)return;
rev[x]^=;
swap(c[x][],c[x][]);
}
inline void pushdown(int x)
{
if(!x)return;
if(tag[x]){add(c[x][],tag[x]);add(c[x][],tag[x]);tag[x]=;}
if(rev[x]){rever(c[x][]);rever(c[x][]);rev[x]=;}
}
inline int find(int x,int k)
{
pushdown(x);
int l=c[x][],r=c[x][];
if(s[l]+==k)return x;
else if(s[l]>=k)return find(l,k);
else return find(r,k-s[l]-);
}
inline void split(int l,int r)
{
t1=find(rt,l);t2=find(rt,r);
splay(t1,rt);splay(t2,c[rt][]);
}
inline void build(int l,int r,int f)
{
if(l>r)return;
int x=(l+r)>>;
fa[x]=f;c[f][x>f]=x;
if(l==r){mi[x]=v[x];s[x]=;return;}
build(l,x-,x);build(x+,r,x);
pushup(x);
}
int main()
{
n=read();
for2(i,,n+)v[i]=read();
v[]=v[n+]=mi[]=;tot=n+;
build(,n+,);rt=(+n+)>>;
q=read();char ch[];
while(q--)
{
memset(ch,,sizeof(ch));
scanf("%s",ch);int x=read();
if(ch[]=='D')split(x,x+),c[t2][]=;
else if(ch[]=='I')split(x+,x+),fa[c[t2][]=++tot]=t2,s[tot]=,v[tot]=mi[tot]=read();
else if(ch[]=='L')
{
int y=read(),t=read()%(y-x+);if(!t)continue;
split(y+-t-,y+);int tmp=c[t2][];c[t2][]=;
pushup(t2);pushup(t1);
split(x,x+);c[t2][]=tmp;fa[tmp]=t2;
}
else
{
int y=read();split(x,y+);int z=c[t2][];
if(ch[]=='A')add(z,read());
else if(ch[]=='M')printf("%d\n",mi[z]);
else rever(z);
}
pushup(t2);pushup(t1);
}
return ;
}
splay直接暴力往上居然还快了1s233‘
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 2000000+5
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
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 n,q,tot,fa[maxn],c[maxn][],rt,t1,t2,s[maxn],tag[maxn],mi[maxn],v[maxn];
bool rev[maxn];
inline void pushup(int x)
{
if(!x)return;
int l=c[x][],r=c[x][];
s[x]=s[l]+s[r]+;
mi[x]=min(v[x],min(mi[l],mi[r]));
}
inline void rotate(int x,int &k)
{
int y=fa[x],z=fa[y],l=c[y][]==x,r=l^;
if(y!=k)c[z][c[z][]==y]=x;else k=x;
fa[x]=z;fa[y]=x;fa[c[x][r]]=y;
c[y][l]=c[x][r];c[x][r]=y;
pushup(y);pushup(x);
}
inline void splay(int x,int &k)
{
while(x!=k)rotate(x,k);
}
inline void add(int x,int z)
{
if(!x)return;
mi[x]+=z;tag[x]+=z;v[x]+=z;
}
inline void rever(int x)
{
if(!x)return;
rev[x]^=;
swap(c[x][],c[x][]);
}
inline void pushdown(int x)
{
if(!x)return;
if(tag[x]){add(c[x][],tag[x]);add(c[x][],tag[x]);tag[x]=;}
if(rev[x]){rever(c[x][]);rever(c[x][]);rev[x]=;}
}
inline int find(int x,int k)
{
pushdown(x);
int l=c[x][],r=c[x][];
if(s[l]+==k)return x;
else if(s[l]>=k)return find(l,k);
else return find(r,k-s[l]-);
}
inline void split(int l,int r)
{
t1=find(rt,l);t2=find(rt,r);
splay(t1,rt);splay(t2,c[rt][]);
}
inline void build(int l,int r,int f)
{
if(l>r)return;
int x=(l+r)>>;
fa[x]=f;c[f][x>f]=x;
if(l==r){mi[x]=v[x];s[x]=;return;}
build(l,x-,x);build(x+,r,x);
pushup(x);
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for2(i,,n+)v[i]=read();
v[]=v[n+]=mi[]=;tot=n+;
build(,n+,);rt=(+n+)>>;
q=read();char ch[];
while(q--)
{
memset(ch,,sizeof(ch));
scanf("%s",ch);int x=read();
if(ch[]=='D')split(x,x+),c[t2][]=;
else if(ch[]=='I')split(x+,x+),fa[c[t2][]=++tot]=t2,s[tot]=,v[tot]=mi[tot]=read();
else if(ch[]=='L')
{
int y=read(),t=read()%(y-x+);if(!t)continue;
split(y+-t-,y+);int tmp=c[t2][];c[t2][]=;
pushup(t2);pushup(t1);
split(x,x+);c[t2][]=tmp;fa[tmp]=t2;
}
else
{
int y=read();split(x,y+);int z=c[t2][];
if(ch[]=='A')add(z,read());
else if(ch[]=='M')printf("%d\n",mi[z]);
else rever(z);
}
pushup(t2);pushup(t1);
}
return ;
}
BZOJ1895: Pku3580 supermemo的更多相关文章
- 【BZOJ1895】Pku3580 supermemo Splay
[BZOJ1895]Pku3580 supermemo Description 给出一个初始序列fA1;A2;:::Ang,要求你编写程序支持如下操作: 1. ADDxyD:给子序列fAx:::Ayg ...
- [bzoj1895][Pku3580]supermemo_非旋转Treap
supermemo bzoj-1895 Pku-3580 题目大意:给定一个n个数的序列,需支持:区间加,区间翻转,区间平移,单点插入,单点删除,查询区间最小值. 注释:$1\le n\le 6.1\ ...
- PKU-3580 SuperMemo(Splay模板题)
SuperMemo 题目链接 Your friend, Jackson is invited to a TV show called SuperMemo in which the participan ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Supermemo背单词7周年纪念
从2007年2月1日开始,用Supermemo背单词7周年了,在2013年11月21日将单词表Reset,重新开始Review以前背过的单词,并慢慢加入听写VOA时遇到的生词.
- poj 3580 SuperMemo
题目连接 http://poj.org/problem?id=3580 SuperMemo Description Your friend, Jackson is invited to a TV sh ...
- 【POJ3580】【splay版】SuperMemo
Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant i ...
- 【POJ3580】【块状链表】SuperMemo
Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant i ...
- 平衡树(Splay):Splaytree POJ 3580 SuperMemo
SuperMemo Description Your friend, Jackson is invited to a TV show called SuperMemo in which ...
随机推荐
- VC++ CTime Format 详解
参考链接: VC++中CTime类Format参数详解 CTime/COleDateTime::Format方法的使用 http://stat.ethz.ch/R-manual/R-devel/lib ...
- sgu 101 domino
题意还算简洁明了,加上有道翻译凑过着读完了题.题意大体上是 给你 n 个多米诺骨牌, 给出每个骨牌两端的数字, 只有数字相同才可以推到, 比如 2-3和3-2.你可以旋转这些多米诺骨牌, 输出一个可以 ...
- Android_Chronometer计时器
最近做一个项目用到Handler 和Message ,开始时不是很明白,不了解其中的内部机制,所以开发起来有点难度,之后自己找了Android 时间服务 这一节的内容,总结了一点关于时间的知识,在这里 ...
- Percona-Server-5.5.15源码安装
[root@localhost rpm]# ll total 19148 -rw-r--r-- 1 root root 562628 Jan 18 2007 bison-2.3-2.1.x86_ ...
- Linux下的I/O复用与epoll详解
前言 I/O多路复用有很多种实现.在linux上,2.4内核前主要是select和poll,自Linux 2.6内核正式引入epoll以来,epoll已经成为了目前实现高性能网络服务器的必备技术.尽管 ...
- normalize.css介绍
Normalize.css 只是一个很小的CSS文件,但它在默认的HTML元素样式上提供了跨浏览器的高度一致性.相比于传统的CSS reset,Normalize.css是一种现代的.为HTML5准备 ...
- Linux时间设置
Linux时间分为系统时间和硬件时间. 查看系统时间:date 将系统时间写入硬件:hwclock --systohc 查看硬件时间:hwclock --show 将硬件时间写入系统:hwclock ...
- json 包含字段及函数的写法
在javascript中写类有多种方式: 1.function()中嵌套function; 2.prototype的方式 ,3.json的方式,如下: <script language=&quo ...
- 推荐一款java的验证码组件——kaptcha
使用方法: 项目中导入kaptcha-2.3.jar包 在web.xml里面新增: <!-- 登陆验证码Kaptcha --> <servlet> <servlet- ...
- 大话F#和C#:是否会重蹈C#失败的覆辙?
F#.net 出来有些年头儿了,将从 VS 2010 起在 .net framework 平台上以“一等公民”身份粉墨登场的它,将会给计算机科技与软件工业带来哪些悲喜剧呢? F# 将扮演一个什么角色? ...