POJ 3321 dfs序+树状数组
来源:互联网 发布:mac系统剪切文件 编辑:程序博客网 时间:2024/05/29 07:10
这题真的很迷,那个vectorE[maxn]就是过不了,改成vector
#include<iostream>#include<cstdio>#include<vector>#include<cstring>using namespace std;typedef long long LL;const int maxn=100005;int N,M,tot;int L[maxn],R[maxn];int c[maxn];vector<vector<int> >E(maxn);int vis[maxn];char s[4];int tmp;void dfs(int x){ L[x]=tot; for(int i=0;i<E[x].size();i++){ tot++; int to=E[x][i]; dfs(to); } R[x]=tot;}int lowbit(int x) //求最低位1的位置所表示的数{ return x&(-x);}void update(int p,int q)// 单点更新c[p] 加上q{ // (其中k为x二进制末尾0的个数) while(p<=N) { c[p]+=q; p+=lowbit(p); }}int S(int x) //S(i)表示的是的前i个数的和{ int sum=0; while(x>0) { sum+=c[x]; x-=lowbit(x); } return sum;}void init(){ for(int i=1;i<=N;i++){ vis[i]=1; update(i,1); } tot=1;}int main(){ scanf("%d",&N); init(); for(int i=1;i<=N-1;i++){ int u,v; scanf("%d%d",&u,&v); E[u].push_back(v); } dfs(1); scanf("%d",&M); while(M--){ scanf("%s%d",s,&tmp); if(s[0]=='Q'){ printf("%d\n",S(R[tmp])-S(L[tmp]-1)); } else { if(vis[tmp]){ update(L[tmp],-1); } else { update(L[tmp],1); } vis[tmp]=!vis[tmp]; } } return 0;}
0 0
- POJ 3321(dfs序+树状数组)
- dfs 序 + 树状数组 poj 3321
- POJ 3321 dfs序+树状数组
- poj 3321(dfs序&&树状数组)
- poj 3321 dfs + 树状数组
- poj 3321 dfs+树状数组
- POJ 3321 树状数组+DFS
- POJ 3321 Apple Tree(dfs序 + 树状数组)
- POJ 3321 Apple Tree(dfs序+树状数组)
- 【poj 3321】 Apple Tree 树状数组+dfs序
- POJ 3321Apple Tree(dfs序 树状数组)
- poj 3321 Apple Tree(dfs序+树状数组求和模型)
- POJ 3321 Ultra-QuickSort(树状数组+DFS序)
- POJ 3321 Apple Tree(dfs序 + 树状数组)
- 【poj】 3321 Apple Tree dfs序+树状数组
- POJ 3321-Apple Tree(DFS序+树状数组)
- poj 3321 Apple Tree 树状数组 dfs序
- POJ 3321 Apple Tree dfs序 树状数组
- C语言回炉(1)
- listview的使用及自定义baseAdapter
- 打印
- 什么是知网小论文查重系统?
- 字符串学习
- POJ 3321 dfs序+树状数组
- Android之gson操作系列3之fromjson
- linux6
- NOIP 2009 普及组 复赛 score 分数线划定
- N×N数字
- Spring MVC接受XML格式的数据
- 用C语言实现猜数字游戏
- "List cannot be resolved to a type"错误的解决方法
- 用List模拟实现STL下的queue队列