链接:http://cogs.pro/cogs/problem/problem.php?pid=339

题意……我还用说么……OI有史以来最毒瘤数据结构题……

只能说精神低落的时候来上一发,真是神清气爽,完全忘了自己的抑郁症……说实在的,做这道题之前我抑郁症又犯了,但做完这道题,抑郁症是什么?

这个效果大概就是我说的这个东西:

抑郁症患者表示忘记了自杀的念头,忘记了自己没有妹子的事实,忘记了各种催泪番的悲惨结局,忘记了四月是你的谎言,忘记了白色相簿2,忘记了秒速5厘米,忘记了未闻花名,忘记了CLANNAD,忘记了日在校园(滑稽),忘记了零使小说原结局,忘记了FSN天天讲的“不可能每个人都幸福”,忘记了各种电视剧的悲剧结局,忘记了各种村上式结局,忘记了社会的阴暗面,只看见了人生的美好……

  1 #include<iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<algorithm>
  5 using namespace std;
  6 const int inf=0x3f3f3f3f;
  7 int n,m,cnt,c[500010];
  8 struct node
  9 {
 10     int lsum,rsum,totsum,maxsum,size,dk,dv,v,k;
 11     bool rev;
 12     node *ch[2],*pa;
 13     void init(int kk, int vv)
 14     {
 15         k=kk;v=vv;size=1;
 16         dv=inf;
 17         totsum=lsum=rsum=maxsum=v;
 18         ch[0]=ch[1]=pa=0;dk=rev=0;
 19     }
 20 }*root,*MIN,*MAX,*p;
 21 void pushdown(node *x)
 22 {
 23     if(x->dv<inf)
 24     {
 25         x->v=x->dv; x->totsum=x->v*x->size;
 26         x->lsum=x->rsum=x->maxsum=max(x->v,x->totsum);
 27         if(x->ch[0])x->ch[0]->dv=x->dv;
 28         if(x->ch[1])x->ch[1]->dv=x->dv;
 29         x->dv=inf;
 30     }
 31     if(x->dk)
 32     {
 33         x->k+=x->dk;
 34         if(x->ch[0])x->ch[0]->dk+=x->dk;
 35         if(x->ch[1])x->ch[1]->dk+=x->dk;
 36         x->dk=0;
 37     }
 38     if(x->rev)
 39     {
 40         int sl=0, sr=0;
 41         if(x->ch[0])sl=x->ch[0]->size,x->ch[0]->rev=!(x->ch[0]->rev);
 42         if(x->ch[1])sr=x->ch[1]->size,x->ch[1]->rev=!(x->ch[1]->rev);
 43         x->k=x->k-sl+sr;
 44         if(x->ch[0])x->ch[0]->dk+=sr+1;
 45         if(x->ch[1])x->ch[1]->dk+=-sl-1;
 46         swap(x->ch[0],x->ch[1]);
 47         swap(x->lsum,x->rsum);
 48         x->rev=false;
 49     }
 50 }
 51 void update(node *x)
 52 {
 53     pushdown(x);
 54     if(x->ch[0])pushdown(x->ch[0]);
 55     if(x->ch[1])pushdown(x->ch[1]);
 56     int t;
 57     x->size=1;
 58     if(x->ch[0])x->size+=x->ch[0]->size;
 59     if(x->ch[1])x->size+=x->ch[1]->size;
 60     x->totsum=x->v;
 61     if(x->ch[0])x->totsum+=x->ch[0]->totsum;
 62     if(x->ch[1])x->totsum+=x->ch[1]->totsum;
 63     t=x->v;
 64     if(x->ch[0])t+=max(0,x->ch[0]->rsum);
 65     if(x->ch[1])t+=max(0,x->ch[1]->lsum);
 66     if(x->ch[0])t=max(t,x->ch[0]->maxsum);
 67     if(x->ch[1])t=max(t,x->ch[1]->maxsum);
 68     x->maxsum=t;
 69     if(x->ch[0])
 70     {
 71         t=max(x->ch[0]->lsum,x->ch[0]->totsum+x->v);
 72         if(x->ch[1])t=max(t,x->ch[0]->totsum + x->v + max(0,x->ch[1]->lsum) );
 73     }
 74     else if(x->ch[1])t=x->v+max(0,x->ch[1]->lsum);
 75     x->lsum=t;
 76     if(x->ch[1])
 77     {
 78         t=max(x->ch[1]->rsum,x->v+x->ch[1]->totsum);
 79         if(x->ch[0])t=max(t,x->ch[1]->totsum + x->v + max(0,x->ch[0]->rsum));
 80     }
 81     else if(x->ch[0])t=x->v+max(0,x->ch[0]->rsum);
 82     x->rsum=t;
 83 }
 84 void zig(node *x)
 85 {
 86     node *y=x->pa;
 87     pushdown(y),pushdown(x);
 88     if(y->pa->ch[0]==y)y->pa->ch[0]=x;
 89     else y->pa->ch[1]=x;
 90     x->pa=y->pa;
 91     y->ch[0]=x->ch[1]; if(x->ch[1])x->ch[1]->pa=y;
 92     x->ch[1]=y;y->pa=x;
 93     update(y);update(x);
 94 }
 95 void zag(node *x)
 96 {
 97     node *y=x->pa;
 98     pushdown(y),pushdown(x);
 99     if(y->pa->ch[0]==y)y->pa->ch[0]=x; else y->pa->ch[1]=x;
100     x->pa=y->pa;
101     y->ch[1]=x->ch[0]; if(x->ch[0])x->ch[0]->pa=y;
102     x->ch[0]=y;y->pa=x;
103     update(y);update(x);
104 }
105 void splay(node *x, node *F)
106 {
107     while(x->pa!=F)
108     {
109         node *y=x->pa;
110         if(y->pa==F)
111             if(y->ch[0]==x)zig(x);
112             else zag(x);
113         else
114             if(y->pa->ch[0]==y)
115                 if(y->ch[0]==x)zig(y),zig(x);
116                 else zag(x),zig(x);
117             else
118                 if(y->ch[1]==x)zag(y),zag(x);
119                 else zig(x),zag(x);
120     }
121 }
122 node* find(node *x, int k)
123 {
124     node *t;
125     pushdown(x);
126     if(x->k==k)t=x;
127     if(x->k>k)t=find(x->ch[0],k);
128     if(x->k<k)t=find(x->ch[1],k);
129     update(x);
130     return t;
131 }
132 node* get(int k, int v)
133 {
134     node *t;
135     t=p;p=p->pa;
136     if(p->ch[0]==t)p->ch[0]=0;else p->ch[1]=0;
137     while(p->ch[0]||p->ch[1])
138         if(p->ch[0])p=p->ch[0];else p=p->ch[1];
139     t->init(k,v);
140     return t;
141 }
142 void ins(node *t)
143 {
144     p->ch[0]=t;t->pa=p;
145     while(p->ch[0]||p->ch[1])
146         if(p->ch[0])p=p->ch[0];
147         else p=p->ch[1];
148 }
149 node* build(int l, int r)
150 {
151     int mid=(l+r)>>1;
152     node *TMP=get(mid,c[mid]);
153     if(l==r)return TMP;
154     if(l!=mid)
155     {
156         TMP->ch[0]=build(l,mid-1);
157         TMP->ch[0]->pa=TMP;
158     }
159     TMP->ch[1]=build(mid+1,r),TMP->ch[1]->pa=TMP;
160     update(TMP);
161     return TMP;
162 }
163 int haha()
164 {
165     freopen("seq2005.in","r",stdin);
166     freopen("seq2005.out","w",stdout);
167     char s[25],ch;int x,pos,tot;
168     node *t,*tmp;
169     p=new node;
170     for(int i=2;i<=500005;i++)
171     {
172         t=new node;
173         t->init(0,0);
174         t->pa=p,p->ch[1]=t;
175         p=t;
176     }
177     scanf("%d%d",&n,&m);
178     {
179         cnt=0;
180         MIN=get(0,0);
181         MAX=get(1,0);
182         root=get(123,0);
183         root->ch[0]=MIN;MIN->pa=root;
184         MIN->ch[1]=MAX;MAX->pa=MIN;
185         for(int i=1;i<=n;i++)scanf("%d",&c[i]);
186         MAX->k+=n;
187         MAX->ch[0]=build(1,n);MAX->ch[0]->pa=MAX;
188         update(MAX);update(MIN);
189         update(MAX);update(MIN);
190         for(int i=1;i<=m;i++)
191         {
192             scanf("%s",s);
193             switch(s[0])
194             {
195                 case 'I':scanf("%d%d",&pos,&tot);
196                             for(int j=pos+1;j<=pos+tot;j++)scanf("%d",&c[j]);
197                             tmp=find(root->ch[0],pos);
198                             t=find(root->ch[0],pos+1);
199                             splay(tmp,root);splay(t,tmp);
200                             t->dk+=tot;pushdown(t);
201                             t->ch[0]=build(pos+1,pos+tot);
202                             t->ch[0]->pa=t;
203                             update(t);update(tmp);
204                             break;
205                 case 'D':scanf("%d%d",&pos,&tot);
206                             if(!tot)break;
207                             tmp=find(root->ch[0],pos-1);t=find(root->ch[0],pos+tot);
208                             splay(tmp,root);splay(t,tmp);
209                             ins(t->ch[0]);t->ch[0]=0;
210                             t->dk-=tot;pushdown(t);
211                             update(t);update(tmp);
212                             break;
213                 case 'R':scanf("%d%d",&pos,&tot);
214                             tmp=find(root->ch[0],pos-1);
215                             t=find(root->ch[0],pos+tot);
216                             splay(tmp,root);splay(t,tmp);
217                             update(tmp);
218                             t->ch[0]->rev=!(t->ch[0]->rev);
219                             break;
220                 case 'G':scanf("%d%d",&pos,&tot);
221                             if(!tot)
222                             {
223                                 puts("0");
224                                 break;
225                             }
226                            tmp=find(root->ch[0],pos-1);t=find(root->ch[0],pos+tot);
227                            splay(tmp,root);splay(t,tmp);
228                            printf("%d\n",t->ch[0]->totsum);
229                            break;
230                 case 'M':
231                         if(s[2]=='K')
232                         {
233                             scanf("%d%d%d",&pos,&tot,&c[0]);
234                             if(!tot)break;
235                             tmp=find(root->ch[0],pos-1);t=find(root->ch[0],pos+tot);
236                             splay(tmp,root);splay(t,tmp);
237                             t->ch[0]->dv=c[0];pushdown(t->ch[0]);
238                             update(t);update(tmp);
239                             break;
240                         }
241                         splay(MIN,root);splay(MAX,MIN);
242                         pushdown(MAX->ch[0]);
243                         printf("%d\n",MAX->ch[0]->maxsum);
244             }
245         }
246     }
247 }
248 int sb=haha();
249 int main(){;}

cogs339

转载于:https://www.cnblogs.com/Loser-of-Life/p/7265679.html

cogs339 维修数列 ……相关推荐

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

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

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

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

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

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

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

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

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

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

  6. BZOJ1500维修数列 [待修缮]

    在这里存一波splay模板题,啃起来有点难.. Description 请写一个程序,要求维护一个数列,支持以下 6 种操作: 请注意,格式栏 中的下划线' _ '表示实际输入文件中的空格 Input ...

  7. BZOJ 1500 维修数列

    Splay序列操作的大模板题 这个真的是噩梦..调了整整一个晚上,可以说完全被榨干了orz.. 因为我的splay写的实在是太丑了,手动加的哨兵节点,开头忘记pushup了,找了一晚上才找到... 还 ...

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

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

  9. bzoj 1500 [NOI 2005] 维修数列

    题目大意不多说了 貌似每个苦逼的acmer都要做一下这个splay树的模版题目吧 还是有很多操作的,估计够以后当模版了.... 1 #include <cstdio> 2 #include ...

  10. 【BZOJ1500】【codevs1758】维修数列,简析Splay的综合操作

    Time:2016.05.12 Author:xiaoyimi 转载注明出处谢谢 传送门1 传送门2 思路: 我的天啊! Splay大板子! 调了好久啊! 这里的Splay没有判断的key值,换一种说 ...

最新文章

  1. 局部敏感哈希算法的实现
  2. 智能车竞赛技术报告 | 双车接力组 - 沈阳航空航天大学 - 精神小车成双 - 双轮车
  3. 吗咿呀嘿,超分,让照片动起来PaddleGAN
  4. DBMS_SQL系统包的使用
  5. 【论文翻译】统一知识图谱学习和建议:更好地理解用户偏好
  6. java容器遍历_高效遍历Java容器详解
  7. Linux用户管理命令(第二版)
  8. geforce experience不能登录_青椒第二课堂禁毒平台|官方网站登录
  9. statspack report分析
  10. Wordnet 与 Hownet 比较
  11. 采用qt技术,开发OFD电子文档阅读器
  12. Python设置excel单元格格式
  13. 1_科普—什么是GNU?什么是GPL协议?GNU和Linux是怎么结合在一起的?
  14. 2019年 电赛C题 全国大学生电子设计竞赛试题解析与总结
  15. 科普硬解,软解,gpu,dsp等等的关系
  16. oracle误删了表怎么恢复数据,oracle误删除表或者表数据的恢复方法总结
  17. 服务器怎么增加独立显卡,dell服务器设置独立显卡(dell服务器加显卡)
  18. Continuous Integration 对 ABAP 技术栈来说意味着什么
  19. 苹果cms免费自适应模板下载
  20. 2022年第四届河南省CCPC大学生程序设计竞赛代码+简单思路(退役战了算是,还好金了)

热门文章

  1. visual studio code打不开
  2. mtu设置--解决部分网站打不开的问题
  3. (前端发邮件)vue中使用smtp.js发送邮件
  4. 密西根州立大学副教授汤继良:我的人生总有神奇的GPS
  5. 怎么批量在多个文件夹名称后面加上数字序号或者日期时间序号?
  6. OpenCC for PHP 简繁体转换
  7. 三星手机com.android.systemservice卸载,完美卸载 系统程序卸载就用System App Remover
  8. 分辨率、像素和PPI
  9. 坦克大战的网络对战实现C++(客户端+服务端)
  10. 工厂模式 (简单工厂、工厂方法、抽象工厂)