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. 12_ServletConfig对象

    [ServletConfig对象简述] 在Servlet的配置文件中,可以使用一个或多个<init-param>标签为Servlet配置一些初始化参数. 当Servlet配置了初始化参数后 ...

  2. C# 调用load事件

    在一个函数或者事件中调用另外的事件,例如调用Load事件 private void EventForm_Load(object sender, EventArgs e) { //相关内容 } priv ...

  3. bat里如何用相对路径

    在bat中直接使用绝对路径没有问题,但是文件传到其他地方时,绝对路径会发生改变,因此想通过使用相对路径来解决. 可以通过在bat获取当前bat所在的目录,然后cd 该目录来解决该问题 在bat前面增加 ...

  4. [cocos2d-x 2.0.4][iOS7]不能全屏问题

    本篇文章由:http://www.sollyu.com/cocos2d-x-2-0-4-ios7-cannot-be-full-screen-problem/ 说明 ▼ 症状如下图 解决 打开你工程的 ...

  5. nginx 默认会把header里的参数去掉下划线

    做token验证的时候遇到问题:在本地可以获取前端header传的参数,但是部署到服务器获取的就是null(服务器地址用nginx做了代理) 原因: nginx代理默认会把header的参数的 &qu ...

  6. 【nodemailer】 初试

    nodemailer 是什么? 简单的讲nodemailer就是用来发送邮件的.最近的一个项目需要向客户的注册邮箱发送验证连接,研究了一下. 刚开始我以为nodemailer还可以用来接收邮件,看了好 ...

  7. C++中const修饰基本数据类型、指针、引用、对象

    const修饰基本数据类型 #include <iostream> using namespace std; void main(){ const int a = 1; const cha ...

  8. 干货:Web应用上线之前程序员应该了解的技术细节

    [伯乐在线注]:<Web 应用上线前,程序员应考虑哪些技术细节呢?>这是 StackExchange 上面的一个经典问题贴. 最赞回复有 2200+ 顶,虽然大多数人可能都听过其中大部分内 ...

  9. Python解析生成XML-ElementTree VS minidom

    OS:Windows 7 关键字:Python3.4,XML,ElementTree,minidom 本文介绍用Python解析生成以下XML: <Persons> <Person& ...

  10. HIVE中内连接和左半连接不一致问题

    一.理论 HIVE中都是按等值连接来统计的,理论上两种写法统计结果应该是一致的: 二.实际情况 但实际使用中发现两种写法会返回的结果,总会有一些差距虽然差别不大,但让人很是困惑. 三.原因 当使用jo ...