The 36th ACM/ICPC Asia Regional Beijing Site&&http://acm.hdu.edu.cn/showproblem.php?pid=4046
来源:互联网 发布:巢湖学院网络选修课 编辑:程序博客网 时间:2024/06/07 02:20
比较难的线段树题,,,
#include<iostream>#include<cstdio>#include<string.h>#define N 50005using namespace std;typedef struct NODE{ int l; int r; int key;}Node;Node node[N<<2];char str[N];void build(int t,int l,int r){ node[t].l=l; node[t].r=r; if(r==l) { if(l<=2) {node[t].key=0;return;} if(str[l]=='w'&&str[l-1]=='b'&&str[l-2]=='w') node[t].key=1; else node[t].key=0; return; } int mid=(l+r)>>1; build(t<<1,l,mid); build(t<<1|1,mid+1,r); node[t].key=node[t<<1].key+node[t<<1|1].key;}void update(int t,int l,int r,char ch){ if(node[t].l==l&&node[t].r==r) { str[l]=ch; if(l<=2) return; if(str[l]=='w'&&str[l-1]=='b'&&str[l-2]=='w') node[t].key=1; else node[t].key=0; return ; } if(l>=node[t<<1|1].l) update(t<<1|1,l,r,ch); else if(r<=node[t<<1].r) update(t<<1,l,r,ch); else { update(t<<1,l,node[t<<1].r,ch); update(t<<1|1,node[t<<1|1].l,r,ch); } node[t].key=node[t<<1].key+node[t<<1|1].key;}int Quary(int t,int l,int r){ if(node[t].l==l&&node[t].r==r) return node[t].key; if(l>=node[t<<1|1].l) return Quary(t<<1|1,l,r); else if(r<=node[t<<1].r) return Quary(t<<1,l,r); else return Quary(t<<1,l,node[t<<1].r)+Quary(t<<1|1,node[t<<1|1].l,r);}int main(){ int T; scanf("%d",&T); for(int k=1;k<=T;++k) { printf("Case %d:\n",k); int n,m; scanf("%d%d",&n,&m); str[0]=0; scanf("%s",str+1); build(1,1,n); for(int i=0;i!=m;++i) { int x; scanf("%d",&x); if(x==0) { int y,z; scanf("%d%d",&y,&z); if(z-y+1<3) printf("0\n"); else printf("%d\n",Quary(1,y+3,z+1)); } else { int y; char z; scanf("%d",&y);getchar();scanf("%c",&z); update(1,y+1,y+1,z); if(y+1<n) update(1,y+2,y+2,str[y+2]); if(y+2<n) update(1,y+3,y+3,str[y+3]); } } }return 0;}
- The 36th ACM/ICPC Asia Regional Beijing Site&&http://acm.hdu.edu.cn/showproblem.php?pid=4046
- hdu 4011 The 36th ACM/ICPC Asia Regional Shanghai Site —— WarmupWorking in Beijing
- 4046 Panda(The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest)
- http://acm.hdu.edu.cn/showproblem.php?pid=1005
- http://acm.hdu.edu.cn/showproblem.php?pid=1333
- http://acm.hdu.edu.cn/showproblem.php?pid=2710
- http://acm.hdu.edu.cn/showproblem.php?pid=2866
- http://acm.hdu.edu.cn/showproblem.php?pid=1041
- http://acm.hdu.edu.cn/showproblem.php?pid=1719
- http://acm.hdu.edu.cn/showproblem.php?pid=2136
- http://acm.hdu.edu.cn/showproblem.php?pid=1166
- http://acm.hdu.edu.cn/showproblem.php?pid=3519
- http://acm.hdu.edu.cn/showproblem.php?pid=2446
- http://acm.hdu.edu.cn/showproblem.php?pid=1709
- http://acm.hdu.edu.cn/showproblem.php?pid=1874
- http://acm.hdu.edu.cn/showproblem.php?pid=1863
- http://acm.hdu.edu.cn/showproblem.php?pid=1879
- http://acm.hdu.edu.cn/showproblem.php?pid=1875
- Ubuntu 设置 显示桌面
- 管理信息系统的界面特点
- 音视频线
- Android RadioButton example
- Proverb Feeling -- Two heads are always better then one
- The 36th ACM/ICPC Asia Regional Beijing Site&&http://acm.hdu.edu.cn/showproblem.php?pid=4046
- 整理的腾讯笔试题
- 黑马程序员_java基础加强7_多线程加强
- ORACLE 时间间隔计算
- Jquery change
- 负载平衡
- 限制文本输入
- 【POI】POI简介
- Linux C-----位段类型