1895: Pku3580 supermemo

Time Limit: 15 Sec  Memory Limit: 64 MB
Submit: 77  Solved: 47
[Submit][Status]

Description

给出一个初始序列fA1;A2;:::Ang,要求你编写程序支持如下操作:
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,表示初始序列的长度。
以下n行每行包含一个整数,描述初始的序列。
接下来一行包含一个整数m,表示操作的数目。
以下m行每行描述一个操作。

Output

对于所有"MIN"操作,输出正确的答案,每行一个。

Sample Input

5
1
2
3
4
5
2
ADD 2 4 1
MIN 4 5

Sample Output

5

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的更多相关文章

  1. 【BZOJ1895】Pku3580 supermemo Splay

    [BZOJ1895]Pku3580 supermemo Description 给出一个初始序列fA1;A2;:::Ang,要求你编写程序支持如下操作: 1. ADDxyD:给子序列fAx:::Ayg ...

  2. [bzoj1895][Pku3580]supermemo_非旋转Treap

    supermemo bzoj-1895 Pku-3580 题目大意:给定一个n个数的序列,需支持:区间加,区间翻转,区间平移,单点插入,单点删除,查询区间最小值. 注释:$1\le n\le 6.1\ ...

  3. PKU-3580 SuperMemo(Splay模板题)

    SuperMemo 题目链接 Your friend, Jackson is invited to a TV show called SuperMemo in which the participan ...

  4. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  5. Supermemo背单词7周年纪念

    从2007年2月1日开始,用Supermemo背单词7周年了,在2013年11月21日将单词表Reset,重新开始Review以前背过的单词,并慢慢加入听写VOA时遇到的生词.

  6. poj 3580 SuperMemo

    题目连接 http://poj.org/problem?id=3580 SuperMemo Description Your friend, Jackson is invited to a TV sh ...

  7. 【POJ3580】【splay版】SuperMemo

    Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant i ...

  8. 【POJ3580】【块状链表】SuperMemo

    Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant i ...

  9. 平衡树(Splay):Splaytree POJ 3580 SuperMemo

    SuperMemo         Description Your friend, Jackson is invited to a TV show called SuperMemo in which ...

随机推荐

  1. Intellij IDEA配置优化--转载

    1. 在线激活 安装IntelliJ IDEA 2016.1.2版本后,在联网状态下激活.Help --> Register,选择lisence server,粘贴地址http://www.it ...

  2. android 登陆案例

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABEMAAAJuCAIAAADU3FtnAAAgAElEQVR4nOydZ3Rc1dX3nbXez2+erC

  3. Linux Terminal命令

    Linux Terminal命令 1.Ctrl + a 回到命令行の「行首/head」. 2.Ctrl + e 回到命令行の「行尾/tail」, ctrl + end. 3.Ctrl + w 後向/b ...

  4. Vijos P1325桐桐的糖果计划

    > P1325桐桐的糖果计划 标签:**图结构 强连通分量** 描述 桐桐很喜欢吃棒棒糖.他家处在一大堆糖果店的附近. 但是,他们家的区域经常出现塞车.塞人等情况,这导致他不得不等到塞的车或人走 ...

  5. Windows 键盘操作快捷方式积累

    复制.粘贴: CTRL+C 复制被选择的项目到剪贴板 CTRL+V 粘贴剪贴板中的内容到当前位置 CTRL+X 剪切被选择的项目到剪贴板 Alt+ space + E + P CMD 窗口快速粘贴 关 ...

  6. java 的输入/输出

    java 的输入/输出 java的 I/O是通过java.io包下的类和接口支持, 其中最重要的是5个类,分别是 File,OutputStream,InputStream, Write,Reader ...

  7. python(一)入门

    1.软件环境安装和配置 首先下载属于你的操作系统的对应的python安装包 2.傻瓜化下一步下一步 我直接勾选了配置python到path变量 然后完成 3.cmd命令行中测试一把 表示环境配置成功 ...

  8. 根据版本的不同整理所有的绿色SQL Server

    在这篇论坛文章中,读者可以了解到如何根据不同的SQL Server版本,整理出所有版本的绿色SQL Server的具体方法,详细内容请参考下文: 1. Sqlservr.exe 运行参数 Sql Se ...

  9. 《C和指针》读书笔记——第一章 快速上手

    1.注释代码可以用: #if 0 statements #endif 2.参数被声明为const,表明函数将不会修改函数调用者的所传递的这个参数. 3.scanf("%d",&am ...

  10. C语言小结之结构类型

    C语言小结之结构类型 @刁钻的游戏 (1)枚举型类型enum COLOR {BLACK,RED,BLUE};//声明一种新的数据类型,其值分别为0,1,2但是用BLACK/RED/BLUE代表也可以这 ...