COCI 2010/2011 6th round--STEP【线段树】
2017-07-12 10:55
274 查看
Description
Mirko and Slavko started taking tap dance lessons. This dance consists mostly of tapping the floor witha special kind of shoe. Since Mirko and Slavko are fast learners, they decided to come up with their
own choreography.
Tap dance choreography can be described as a sequence consisting of two letters, ‘L’ and ‘R’. ‘L’ means
that you should tap the floor with your left foot, and ‘R’ with your right foot. Mirko realised that the
most exciting parts of tap dancing are the ones in which you don’t use the same leg twice in a row. He
defined the value of a choreography as the longest subsequence of consecutive elements that doesn’t
contain two consecutive ‘L’s or ‘R’s.
As we all know, designing a choreography can be very challenging, with lots of small changes until it’s
done. For every alteration that Slavko does, he would like to know the current choreography value.
One alteration is changing one ‘L’ to ‘R’, and vice versa.
Before any alterations are made, the choreography consists only of letters ‘L’.
大致意思就是初始给一个长度为N的全是L的串,每次将一个位置修改(L变成R,R变成L),每次修改后求出L和R交替出现的最长的子串长度。
题解
额,跟模板题一样。如果两个位置一样就是0,不一样就是1,答案就是最长的连续的1的长度+1,修改的时候把前后两个位置都改掉就好了。代码
#include<cstdio> #include<cstring> #include<algorithm> #define maxn 200006 using namespace std; inline char nc(){ static char buf[100000],*i=buf,*j=buf; return i==j&&(j=(i=buf)+fread(buf,1,100000,stdin),i==j)?EOF:*i++; } inline int _read(){ char ch=nc();int sum=0; while(!(ch>='0'&&ch<='9'))ch=nc(); while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc(); return sum; } struct data{ int l,r,p,ml,mr,m; }tree[maxn*4]; int n,tet; void build(int p,int l,int r){ tree[p].l=l;tree[p].r=r;tree[p].p=0; if(l==r)return; int mid=(l+r)>>1; build(p<<1,l,mid);build(p<<1|1,mid+1,r); } void update(int p,int k){ if(tree[p].l>k||tree[p].r<k)return; if(tree[p].l==tree[p].r){ tree[p].p=1-tree[p].p; if(tree[p].p)tree[p].m=tree[p].ml=tree[p].mr=1; else tree[p].m=tree[p].ml=tree[p].mr=0; return; } update(p<<1,k);update(p<<1|1,k); if(tree[p<<1].ml==tree[p<<1].r-tree[p<<1].l+1)tree[p].ml=tree[p<<1].ml+tree[p<<1|1].ml; else tree[p].ml=tree[p<<1].ml; if(tree[p<<1|1].mr==tree[p<<1|1].r-tree[p<<1|1].l+1)tree[p].mr=tree[p<<1|1].mr+tree[p<<1].mr; else tree[p].mr=tree[p<<1|1].mr; tree[p].m=max(max(tree[p].ml,tree[p].mr),tree[p<<1].mr+tree[p<<1|1].ml); tree[p].m=max(tree[p].m,max(tree[p<<1].m,tree[p<<1|1].m)); } int main(){ freopen("step.in","r",stdin); freopen("step.out","w",stdout); n=_read();tet=_read(); build(1,1,n-1); while(tet--){ int x=_read(); if(x!=1)update(1,x-1); if(x!=n)update(1,x); printf("%d\n",tree[1].m+1); } return 0; }
相关文章推荐
- COCI 2010/2011 6th round--ABECEDA【拓扑排序】【字符串处理】
- 【线段树】COCI2010-2011(CONTEST#6)[STEP]题解
- COCI 2012/2013 6th round, March 9th, 2013
- [BZOJ3189][Coci2011][扫描线][线段树]Slika
- Codeforces Yandex.Algorithm 2011 Round 1 85D 线段树
- Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树
- 【可持久化线段树】[COCI]白雪公主(white)
- Live Messenger 2011转角遇到TMG 2010
- [BZOJ1828][Usaco2010 Mar]balloc 农场分配(贪心+线段树)
- CodeForces Round 213 Div 2 E Sereja and Brackets 线段树
- Codeforces Round 200 Div1 D Water Tree (树上线段树)
- [Noi2010] D1T2 超级钢琴 (ST表 线段树 主席树)
- bzoj 1835: [ZJOI2010]base 基站选址(线段树优化dp)
- bzoj 2243 [SDOI2011]染色 树剖+线段树
- ACM-2011 Google Code jam Round 1
- 数据结构2011与2010大纲比较
- [bzoj3445][ONTAK2010]Peaks 离线+线段树合并
- 2010~2011手机CPU对比
- BZOJ 2243 [SDOI2011]染色 树链剖分+LCA+区间合并线段树
- BZOJ 1858: [Scoi2010]序列操作( 线段树 )