bzoj 1103: [POI2007]大都市meg 树状数组
来源:互联网 发布:淘宝圣手魔方 编辑:程序博客网 时间:2024/05/18 03:55
一句话题意:将边权修改为0(初始为1)和查询某个点到1的距离。
一开始预处理没有问题吧,然后修改边权只对它管辖的子树有影响。相当于区间修改。然后查分一下用树状数组即可。
AC代码如下:
#include<iostream>#include<cstdio>#include<cstring>#define N 250005using namespace std;int n,m,tot,dfsclk,c[N],bg[N],ed[N],fst[N],pnt[N],nxt[N];int read(){int x=0; char ch=getchar();while (ch<'0' || ch>'9') ch=getchar();while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }return x;}void add(int x,int y){pnt[++tot]=y; nxt[tot]=fst[x]; fst[x]=tot;}void ins(int x,int t){for (; x<=n; x+=x&-x) c[x]+=t;}int getsum(int x){int t=0; for (; x; x-=x&-x) t+=c[x]; return t;}void dfs(int x){bg[x]=++dfsclk; int p;for (p=fst[x]; p; p=nxt[p]) dfs(pnt[p]);ed[x]=dfsclk;}int main(){n=read(); int i,x,y;for (i=1; i<n; i++){x=read(); y=read(); add(x,y);}dfs(1); m=read()+n-1; char ch;for (i=2; i<=n; i++){ ins(bg[i],1); ins(ed[i]+1,-1); }while (m--){ch=getchar(); while (ch<'A' || ch>'Z') ch=getchar();if (ch=='W') printf("%d\n",getsum(bg[read()])); else{x=read(); y=read();ins(bg[y],-1); ins(ed[y]+1,1);}}return 0;}
by lych
2016.3.15
0 0
- bzoj 1103: [POI2007]大都市meg 树状数组
- [dfs序 树状数组] BZOJ 1103 [POI2007]大都市meg
- 【bzoj 1103】[POI2007]大都市meg 树状数组维护dfs序
- BZOJ 1103: [POI2007]大都市meg 树链剖分, 树状数组+DFS序
- [BZOJ]1103: [POI2007]大都市meg dfs序+树状数组
- BZOJ 1103: [POI2007]大都市meg 差分+树状数组
- BZOJ 1103: [POI2007]大都市meg 树上差分 树状数组
- [BZOJ]1103: [POI2007]大都市meg
- 【BZOJ 1103】 [POI2007]大都市meg
- BZOJ 1103: [POI2007]大都市meg
- bzoj-1103 [POI2007]大都市meg
- BZOJ 1103: [POI2007]大都市meg
- BZOJ 1103 [POI2007]大都市meg
- bzoj 1103 POI2007 大都市meg
- 【bzoj 1103】[POI2007]大都市meg
- bzoj 1103 bzoj [POI2007]大都市meg
- bzoj 1103: [POI2007]大都市meg(树链剖分)
- 1103: [POI2007]大都市meg
- 问题汇总のUnable to find expected entry in Release file问题
- Cocos2d-x客户端代码加密
- myeclipse快捷键
- Is there any way to define a min and max value for edittext in android?
- ACM HDU Bone Collector 01背包
- bzoj 1103: [POI2007]大都市meg 树状数组
- linux build commands
- typedef详解
- js阻塞特性
- Arcgis for js,Openlayers中加载GeoJSON
- 2015蓝桥杯试题--三羊献瑞
- 3996: [TJOI2015]线性代数|最小割
- Spring核心概念理解-IoC容器、DI、AOP
- 欢迎使用CSDN-markdown编辑器