POJ2777 线段树+LASY思想
来源:互联网 发布:酷家乐云设计软件 编辑:程序博客网 时间:2024/06/05 09:22
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;const int dmax=301000;int c[dmax];bool p[50];void color(int x,int l,int r,int s,int t,int z){if (c[x]==z)return;if (l==s && r==t){c[x]=z;return;}if (c[x]!=-1){c[x*2]=c[x*2+1]=c[x];c[x]=-1;}int mid=(l+r)>>1;if (t<=mid){color(x*2,l,mid,s,t,z);}else{if (mid<s)color(x*2+1,mid+1,r,s,t,z);else{color(x*2,l,mid,s,mid,z);color(x*2+1,mid+1,r,mid+1,t,z);}}}void call(int x,int l,int r,int s,int t){if (c[x]!=-1){p[c[x]]=1;return;}int mid=(l+r)>>1;if (t<=mid){call(x*2,l,mid,s,t);}else{if (mid<s)call(x*2+1,mid+1,r,s,t);else{call(x*2,l,mid,s,mid);call(x*2+1,mid+1,r,mid+1,t);}}}int main(){int i,j,k,m,n,t,x,y,z,ans;char tmp;c[1]=1;scanf("%d%d%d",&n,&t,&m);getchar();for (i=1;i<=m;i++){tmp=getchar();if (tmp=='C'){scanf("%d%d%d",&x,&y,&z);if (x>y)swap(x,y);color(1,1,n,x,y,z);}else{ans=0;memset(p,0,sizeof(p));scanf("%d%d",&x,&y);if (x>y)swap(x,y);call(1,1,n,x,y);for (j=1;j<=t;j++)if (p[j])ans++;printf("%d\n",ans);}getchar();}return 0;}
0 2
- POJ2777 线段树+LASY思想
- poj2777线段树+lazy思想
- 线段树模板 poj2777
- POJ2777---线段树
- 线段树-POJ2777
- POJ2777(线段树)
- poj2777线段树
- poj2777 线段树
- poj2777(线段树)
- POJ2777线段树....
- POJ2777线段树
- poj2777(线段树)
- POJ2777【线段树】
- POJ2777 Count Color 线段树
- 线段树典型例题--poj2777
- 【poj2777】【线段树】Count Color
- poj2777(延迟更新+线段树)
- 线段树区间更新poj2777
- 汉诺塔
- [更新]基于MFC对话框并使用MCI接口的音乐播放器
- cocoapods 安装使用
- 小常识
- leetcode系列(71)Reorder List
- POJ2777 线段树+LASY思想
- 布鲁斯·威利斯
- Http通信与Socket通信比较:谁更猴塞雷?
- Linux/Unix下的任务管理器-top命令
- redis的事务
- Codevs_P4645 Fibonacci的兔子(枚举+快速幂)
- 最长路径
- [NOIP基础数论]最大公约数和最小公倍数
- 解决wps在windows上弹窗等的流氓行为