[链表 杂题] BZOJ 4432 [Cerc2015]Greenhouse Growth
来源:互联网 发布:摄影美工 编辑:程序博客网 时间:2024/05/22 03:53
只有我觉得神题吗 比C难度还大?
看懂了也不会写 不会告诉你我是看着标程写的
#include<cstdio>#include<cstdlib>#include<algorithm>#include<vector>#define pb push_backusing namespace std;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline void read(int &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}inline void read(char &x){ for (x=nc();x!='A' && x!='B';x=nc());}const int N=300005;struct node;int n,m,T;int cnt[N][4];vector<node*> ev[N][4];struct node{ int lp,rp,h0,t0,g; // 1 A 2 B 3 BOTH node *l,*r; int del; bool GA(){ return l && l->l->H()>H();} bool GB(){ return r && r->r->H()>H();} void get(){ g=GA()|(GB()<<1);} int H(){ return h0+cnt[T][g]-cnt[t0][g];} void modify(){ int dh=abs(l->H()-r->H()),sg=l->g^r->g; if (dh && sg){ int c=cnt[T][sg]+dh; if (c<=m) ev[c][sg].pb(this); } } void wake(){ if (del || l->H()!=r->H()) return; int h=l->H(); node* ret=l; ret->r=r->r; if (ret->r) ret->r->l=ret; ret->lp=l->lp,ret->rp=r->rp,ret->h0=h,ret->t0=T; ret->get(); if (ret->l) ret->l->modify(); if (ret->r) ret->r->modify(); del=1; }}memory[N<<1];int ncnt;int main(){ int h; char c; freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); read(m); node *head=NULL,*pre=NULL,*mid,*cur; for (int i=1;i<=n;i++){ read(h); if (pre && h==pre->h0) { pre->rp=i; continue; } cur=memory+(++ncnt); cur->lp=i,cur->rp=i,cur->h0=h,cur->t0=0; if (pre){ mid=memory+(++ncnt); mid->l=pre,mid->r=cur,pre->r=mid,cur->l=mid; pre->get(); }else head=cur; pre=cur; } pre->get(); for (node* p=head;p->r;p=p->r->r) p->r->modify(); for (T=1;T<=m;++T){ read(c); cnt[T][1]=cnt[T-1][1]+(c=='A'),cnt[T][2]=cnt[T-1][2]+(c=='B'),cnt[T][3]=cnt[T-1][3]+1; for (int g=1;g<=3;g++) for (int i=0;i<(int)ev[cnt[T][g]][g].size();i++) ev[cnt[T][g]][g][i]->wake(); } T=m; for (node* p=head;p;p=p->r->r){ for (int i=p->lp;i<=p->rp;i++) printf("%d%c",p->H(),i==n?'\n':' '); if (!(p->r)) break; } return 0;}
0 0
- [链表 杂题] BZOJ 4432 [Cerc2015]Greenhouse Growth
- 【CERC2015】【BZOJ4432】Greenhouse Growth
- [杂题] BZOJ 4437 [Cerc2015]Looping Labyrinth
- [并查集 杂题] BZOJ 4452 [Cerc2015]Export Estimate
- bzoj 4421: [Cerc2015] Digit Division
- bzoj 4436: [Cerc2015]Kernel Knights
- BZOJ 4451: [Cerc2015]Frightful Formula
- 【bzoj 4451】[Cerc2015]Frightful Formula - 递推
- bzoj 4451: [Cerc2015]Frightful Formula 数学+排列组合
- [乱搞] BZOJ 4436 [Cerc2015]Kernel Knights
- [乱搞] BZOJ 4434 [Cerc2015]Ice Igloos
- BZOJ 4435: [Cerc2015]Juice Junctions tarjan
- Bzoj 4422: [Cerc2015]Cow Confinement(线段树+扫描线)
- 【 bzoj 4452 】 [cerc2015] Export Estimate - 并查集
- [FFT || 递推] BZOJ 4451 [Cerc2015]Frightful Formula
- [扫描线 线段树] BZOJ 4422 [Cerc2015]Cow Confinement
- [边双连通分量 Hash] BZOJ 4435 [Cerc2015]Juice Junctions
- growth
- JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception '
- spring-xml配置bean自动装配
- 简易服务器压力测试工具
- 最少拦截系统
- Inno Setup Compiler 将exe打包setup安装文件
- [链表 杂题] BZOJ 4432 [Cerc2015]Greenhouse Growth
- ATM 系统的面向对象分析与设计之一——问题陈述、词汇表、领域类图
- UDF:时间加减
- Android的别踩白块开发,使用SurfaceView(一)。
- 231. Power of Two
- TortoiseSVN检出项目不完整,缺少文件夹是什么原因?
- Visual Studio Code使用问题
- light oj 1191
- 关于买书