Description

Input

输入的第1 行包含两个数N 和M(M ≤20 000),N 表示初始时数列中数的个数,M表示要进行的操作数目。
第2行包含N个数字,描述初始时的数列。
以下M行,每行一条命令,格式参见问题描述中的表格。
任何时刻数列中最多含有500 000个数,数列中任何一个数字均在[-1 000, 1 000]内。
插入的数字总数不超过4 000 000个,输入文件大小不超过20MBytes。

Output

对于输入数据中的GET-SUM和MAX-SUM操作,向输出文件依次打印结果,每个答案(数字)占一行。

Sample Input

9 8
2 -6 3 5 1 -5 -3 6 3
GET-SUM 5 4
MAX-SUM
INSERT 8 3 -5 7 2
DELETE 12 1
MAKE-SAME 3 3 2
REVERSE 3 6
GET-SUM 5 4
MAX-SUM

Sample Output

-1
10
1
10

HINT

spaly裸题,但依旧不敢保证自己能写出来,并且有很多不会的地方
  1 #include<queue>
  2 #include<cmath>
  3 #include<cstdio>
  4 #include<cstring>
  5 #include<cstdlib>
  6 #include<iostream>
  7 #include<algorithm>
  8 #define inf 1000000000
  9 #define N 1000005
 10 using namespace std;
 11 queue<int> q;
 12 int n,m,rt,sz;
 13 int a[N],id[N],fa[N],c[N][2];
 14 int sum[N],size[N],v[N],mx[N],lx[N],rx[N];
 15 bool tag[N],rev[N];
 16 void updata(int x){
 17     int l=c[x][0],r=c[x][1];
 18     sum[x]=sum[l]+sum[r]+v[x];
 19     size[x]=size[l]+size[r]+1;
 20     mx[x]=max(mx[l],mx[r]);
 21     mx[x]=max(mx[x],rx[l]+v[x]+lx[r]);
 22     lx[x]=max(lx[l],sum[l]+v[x]+lx[r]);//?
 23     rx[x]=max(rx[r],sum[r]+v[x]+rx[l]);
 24 }
 25
 26 void pushdown(int x){
 27     int l=c[x][0],r=c[x][1];
 28     if (tag[x]){
 29         rev[x]=tag[x]=0;
 30         if (l)tag[l]=1,v[l]=v[x],sum[l]=v[x]*size[l];
 31         if (r)tag[r]=1,v[r]=v[x],sum[r]=v[x]*size[r];
 32         if (v[x]>=0){
 33             if (l)lx[l]=rx[l]=mx[l]=sum[l];
 34             if (r)lx[r]=rx[r]=mx[r]=sum[r];
 35         }
 36         else {
 37             if (l)lx[l]=rx[l]=0,mx[l]=v[l];
 38             if (r)lx[r]=rx[r]=0,mx[r]=v[r];
 39         }
 40     }
 41     if (rev[x]){
 42         rev[x]^=1;rev[l]^=1;rev[r]^=1;
 43         swap(lx[l],rx[l]);swap(lx[r],rx[r]);
 44         swap(c[l][0],c[l][1]);swap(c[r][0],c[r][1]);//?
 45     }
 46 }
 47 void rotate(int x,int &k){
 48     int l,r,y=fa[x],z=fa[y];
 49     if (c[y][0]==x) l=0;else l=1;r=l^1;
 50     if (y==k)k=x;
 51     else {if (c[z][0]==y) c[z][0]=x;else c[z][1]=x;}
 52     fa[x]=z;fa[y]=x;fa[c[x][r]]=y;
 53     c[y][l]=c[x][r];c[x][r]=y;
 54     updata(y);updata(x);
 55 }
 56
 57 void splay(int x,int &k){
 58     while (x!=k){
 59         int y=fa[x],z=fa[y];
 60         if (y!=k){
 61             if ((c[z][0]==y)^(c[y][0]==x)) rotate(x,k);
 62             else rotate(y,k);
 63         }
 64         rotate(x,k);
 65     }
 66 }
 67
 68 int find(int k,int rk){
 69     pushdown(k);
 70     int l=c[k][0],r=c[k][1];
 71     if (size[l]+1==rk) return k;
 72     if (size[l]>=rk) return find(l,rk);
 73     return find(r,rk-size[l]-1);
 74 }
 75
 76 int split(int k,int tot){
 77     int x=find(rt,k),y=find(rt,k+tot+1);
 78     splay(x,rt);splay(y,c[x][1]);
 79     return c[y][0];
 80 }
 81
 82 void build(int l,int r,int f){
 83     if (l>r) return;
 84     int mid=(l+r)>>1,last=id[f],now=id[mid];
 85     if (l==r){
 86         sum[now]=a[l];size[now]=1;
 87         tag[now]=rev[now]=0;
 88         if (a[l]>=0) lx[now]=rx[now]=mx[now]=a[l];
 89         else lx[now]=rx[now]=0,mx[now]=a[l];
 90     }
 91     else build(l,mid-1,mid),build(mid+1,r,mid);
 92     v[now]=a[mid];fa[now]=last;updata(now);
 93     c[last][mid>=f]=now;
 94 }
 95 void insert(int k,int tot){
 96     for (int i=1;i<=tot;i++){
 97         if(!q.empty())id[i]=q.front(),q.pop();
 98         else id[i]=++sz;
 99         scanf("%d",&a[i]);
100     }
101     build(1,tot,0);int z=id[(1+tot)>>1];
102     int x=find(rt,k+1),y=find(rt,k+2);
103     splay(x,rt);splay(y,c[x][1]);
104     c[y][0]=z;fa[z]=y;
105     updata(y);updata(x);
106 }
107
108 void rec(int x){
109     if (!x) return;
110     int l=c[x][0],r=c[x][1];
111     rec(l);rec(r);q.push(x);
112     fa[x]=c[x][0]=c[x][1]=tag[x]=rev[x]=0;
113 }
114
115 void erase(int k,int tot){
116     int x=split(k,tot),y=fa[x];
117     rec(x);c[y][0]=0;
118     updata(y);updata(fa[y]);
119 }
120
121 void modify(int k,int tot,int val){
122     int x=split(k,tot),y=fa[x];
123     v[x]=val;tag[x]=1;sum[x]=size[x]*val;
124     if (val>=0)lx[x]=rx[x]=mx[x]=sum[x];
125     else lx[x]=rx[x]=0,mx[x]=val;
126     updata(y);updata(fa[y]);
127 }
128
129 void rever(int k,int tot){
130     int x=split(k,tot),y=fa[x];
131     if (!tag[x]){//或许会节省一点时间
132         rev[x]^=1;
133         swap(c[x][0],c[x][1]);
134         swap(lx[x],rx[x]);
135         updata(y);updata(fa[y]);
136     }
137 }
138
139 void query(int k,int tot){
140     int x=split(k,tot);
141     printf("%d\n",sum[x]);
142 }
143
144 int main(){
145     scanf("%d%d",&n,&m);
146     mx[0]=a[1]=a[n+2]=-inf;
147     for(int i=1;i<=n;i++)scanf("%d",&a[i+1]);
148     for(int i=1;i<=n+2;i++)id[i]=i;
149     build(1,n+2,0);
150     rt=(n+3)>>1;sz=n+2;
151     int k,tot,val;
152     char ch[10];
153     while(m--)
154     {   //printf("%d\n",mx[rt]);
155         scanf("%s",ch);
156         if(ch[0]!='M'||ch[2]!='X')scanf("%d%d",&k,&tot);
157         if(ch[0]=='I')insert(k,tot);
158         if(ch[0]=='D')erase(k,tot);
159         if(ch[0]=='M')
160         {
161             if(ch[2]=='X')printf("%d\n",mx[rt]);
162             else scanf("%d",&val),modify(k,tot,val);
163         }
164         if(ch[0]=='R')rever(k,tot);
165         if(ch[0]=='G')query(k,tot);
166     }
167     return 0;
168 }

转载于:https://www.cnblogs.com/wuminyan/p/5154164.html

【BZOJ1500】[NOI2005]维修数列相关推荐

  1. [BZOJ1500][NOI2005]维修数列(splay)

    1500: [NOI2005]维修数列 Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 16266  Solved: 5410 [Submit][Sta ...

  2. BZOJ1500 [NOI2005]维修数列(Splay tree)

    [Submit][Status][Discuss] Description 请写一个程序,要求维护一个数列,支持以下 6 种操作: 请注意,格式栏 中的下划线' _ '表示实际输入文件中的空格 Inp ...

  3. bzoj1500: [NOI2005]维修数列

    模板题 之前还写了点铺垫题 bzoj3223 教你如何reverse bzoj1507 教你如何维护序列 bzoj1269 教你如何维护序列&reverse 然后再做这个题就好多啦 #incl ...

  4. 【BZOJ1500】[NOI2005]维修数列 Splay

    [BZOJ1500][NOI2005]维修数列 Description Input 输入的第1 行包含两个数N 和M(M ≤20 000),N 表示初始时数列中数的个数,M表示要进行的操作数目. 第2 ...

  5. 数据结构之fhq-treap——Chef and Sets,[HNOI2012]永无乡,Play with Chain,[NOI2005]维修数列(结构体版代码)

    因为非常板,所以主要是代码 Tyvj 1728 普通平衡树 Chef and Sets [HNOI2012]永无乡 Play with Chain [NOI2005]维修数列 题目很水,所以可能会出现 ...

  6. [BZOJ 1500] [NOI2005] 维修数列

    题目链接:BZOJ - 1500 题目分析 我要先说一下,这道题我写了一晚上,然后Debug了一整个白天..........再一次被自己的蒟蒻程度震惊= = 这道题是传说中的Splay维护数列的Bos ...

  7. 1500: [NOI2005]维修数列 (Splay)

    1W1A(inf开太大) #include<algorithm> #include<iostream> #include<cstring> #include< ...

  8. BZOJ 1500 Luogu P2042 [NOI2005] 维护数列 (Splay)

    BZOJ 1500 Luogu P2042 [NOI2005] 维护数列 (Splay) 手动博客搬家: 本文发表于20180825 00:34:49, 原地址https://blog.csdn.ne ...

  9. 数据结构(Splay平衡树):COGS 339. [NOI2005] 维护数列

    339. [NOI2005] 维护数列 时间限制:3 s   内存限制:256 MB [问题描述] 请写一个程序,要求维护一个数列,支持以下 6 种操作:(请注意,格式栏 中的下划线' _ '表示实际 ...

  10. [bzoj1500 维修数列](NOI2005) (splay)

    真的是太弱了TAT...光是把代码码出来就花了3h..还调了快1h才弄完T_T 号称考你会不会splay(当然通过条件是1h内AC..吓傻)... 黄学长的题解:http://hzwer.com/28 ...

最新文章

  1. 在Ubuntu 14.04上设置生产环境可用的Node.js
  2. 《Python Cookbook 3rd》笔记(5.19):创建临时文件和文件夹
  3. day27 CRM delete action 嵌入CRM
  4. Flutter实战之AS快键键
  5. 来了 | Python 官方发布整套中文PDF文档(共27本)
  6. matlab求刚度,求整体刚度矩阵matlab程序
  7. java能做称重软件_java实现砝码称重
  8. mac打开airplay(隔空播放)
  9. css局域样式使用scoped,防止样式污染
  10. java里 输出101-150中的素数
  11. JAVA面向对象编程学习 (1)语法基础与类与对象
  12. 打开catia界面全是白色怎么办_CATIA复合材料设计教程:1.软件安装
  13. 在爱情里不会委曲求全,活的非常自我,态度十分坚决的三个生肖
  14. MYSQL数据库下载安装(Windows版本)
  15. 微信小程序:意见反馈制作(1)(可加图片)
  16. STM32 VCP PC端安装驱动失败的问题解决
  17. html网页页尾,终于认识网页页尾设计注意技巧
  18. linux 命令 置顶,[置顶] Linux命令惯用法
  19. hashmap是有序的吗_这里有675道Java面试题,你准备好接招了吗?(完整版)
  20. 使用remote desktop manager管理windows远程桌面连接

热门文章

  1. oracle判断一个值不在记录中,Oracle: DELETE前不需SELECT判断记录是否存在,INSERT前不需SELECT判断是否有若干字段值重复的记录。...
  2. stm32for循环几个机械周期_带你了解包装机械设备的可调度性分析
  3. 合肥工业大学宣城校区计算机大赛,合肥工业大学宣城校区学子在2019年全国大学生电子设计竞赛中喜获佳绩...
  4. windows 2008服务器还原系统,windows 2008服务器系统
  5. h2事务与mysql_H2数据库事务提交失败
  6. java 位与 取模_【Java基础】14、位与()操作与快速取模
  7. 导出文件后打不开_微信收到CAD图纸打不开?只要有这个神器,手机即可1秒轻松打开...
  8. python3之线程
  9. Design System 中的 Design Token
  10. Apache静态缓存配置