题目链接:

大概是:修改点值,求子树节点为0有多少个,

DFS序后,BIT 询问,修改

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 typedef long long ll;
 5 
 6 #define N 223456
 7 ll val[N];
 8 int l[N],r[N];
 9 int t=;
 int f[N];
 int lowbit(int x)
 {
     return x&-x;
 }
 void update(int x,int v)
 {
     while (x<N)
     {
         f[x]+=v;
         x+=lowbit(x);
     }
 }
 ll query(int x)
 {
     ll s=;
     while (x)
     {
         s+=f[x];
         x-=lowbit(x);
     }
     return s;
 }
 vector<int>mp[N];
 void dfs(int u,int pre)
 {
     l[u]=t++;
     for (int i=;i<mp[u].size();i++)
     {
         int v=mp[u][i];
         if (v==pre) continue;
         dfs(v,u);
     }
     r[u]=t-;
 }
 
 
 int main()
 {
     int n,Q;
     scanf("%d%d",&n,&Q);
     for (int i=;i<n;i++)
     {
         int x,y;
         scanf("%d%d",&x,&y);
         mp[x].push_back(y);
         mp[y].push_back(x);
     }
     dfs(,);
     for (int i=;i<=n;i++)
     {
         scanf("%d",&val[i]);
         if (val[i]==) update(l[i],);
     }
     while (Q--)
     {
         char s[];
         scanf("%s",s);
         if (s[]=='U')
         {
             int u,v;
             scanf("%d%d",&u,&v);
             if (val[u]==) update(l[u],-);
             val[u]+=v;
             if (val[u]==) update(l[u],);
         }else
         {
             int x;
             scanf("%d",&x);
             int ans=query(r[x])-query(l[x]-);
             printf("%d\n",ans);
         }
     }
     return ;
 }

codechef Tree and Queries Solved的更多相关文章

  1. [Codeforces Round #221 (Div. 1)][D. Tree and Queries]

    题目链接:375D - Tree and Queries 题目大意:给你一个有n个点的树,每个点都有其对应的颜色,给出m次询问(v,k),问v的子树中有多少种颜色至少出现k次 题解:先对所有的询问进行 ...

  2. Codeforces 375D Tree and Queries(DFS序+莫队+树状数组)

    题目链接  Tree and Queries 题目大意  给出一棵树和每个节点的颜色.每次询问$vj, kj$ 你需要回答在以$vj$为根的子树中满足条件的的颜色数目, 条件:具有该颜色的节点数量至少 ...

  3. CodeForces 375D Tree and Queries 莫队||DFS序

    Tree and Queries 题意:有一颗以1号节点为根的树,每一个节点有一个自己的颜色,求出节点v的子数上颜色出现次数>=k的颜色种类. 题解:使用莫队处理这个问题,将树转变成DFS序区间 ...

  4. codeforces 375D:Tree and Queries

    Description You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. ...

  5. CF375D Tree and Queries

    题意翻译 给出一棵 n 个结点的树,每个结点有一个颜色 c i . 询问 q 次,每次询问以 v 结点为根的子树中,出现次数 ≥k 的颜色有多少种.树的根节点是1. 感谢@elijahqi 提供的翻译 ...

  6. CodeForces 376F Tree and Queries(假·树上莫队)

    You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. We will ass ...

  7. Codeforces 375 D Tree and Queries

    Discription You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. ...

  8. CodeForces - 375D Tree and Queries (莫队+dfs序+树状数组)

    You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. We will ass ...

  9. CodeChef DISTNUM2 Easy Queries 节点数组线段树

    Description You are given an array A consisting of N positive integers. You have to answer Q queries ...

随机推荐

  1. SVN的使用二

    一,打开SCM 在xcode中,点击菜单: File -> Source Control –> Repositories 二,连接SVN服务器 1, 2,配置SVN服务器地址(http:/ ...

  2. html中注释的问题

    在修改jsp页面的时候遇到了一个有点难懂的注释,mark一下 <script> <!-- alert("js code"); //--> </scri ...

  3. Mac OS 终端强化美化:iterm2 + zsh + oh~my~zsh 设置教程

    为了获得更好的排版效果,文章改用markdown撰写,故重发一次. 前言 mac自带的terminal终端没有文件名高亮等功能,而且界面不是很好看,故今晚学舍友折腾了终端,可以让自己使用起来更加方便, ...

  4. Linux基础学习-Postfix与Dovecot部署邮件系统

    电子邮件系统 电子邮件系统是我们在日常工作.生活中最常用的一种网络服务. 部署基础的电子邮件系统 [root@qdlinux ~]# yum install bind-chroot -y [root@ ...

  5. php登录加密加盐

    1         背景 涉及身份验证的系统都需要存储用户的认证信息,常用的用户认证方式主要为用户名和密码的方式,为了安全起见,用户输入的密码需要保存为密文形式,可采用已公开的不可逆的hash加密算法 ...

  6. NGINX宏观手记

    一.这里的优化主要是指对nginx的配置优化,一般来说nginx配置文件中对优化比较有作用的主要有以下几项: nginx进程数,建议按照cpu数目来指定,一般跟cpu核数相同或为它的倍数. ``` w ...

  7. 时间格式的处理和数据填充和分页---laravel

    时间格式文档地址:http://carbon.nesbot.com/docs/ 这是些时间格式,只需要我们这么做就可以 我们在模板层,找到对应的模型对象那里进行处理就可以啦 2018-11-08 16 ...

  8. mysql 慢查询日志 pt-query-digest 工具安装

    介绍:pt-query-digest是用于分析mysql慢查询的一个工具,它可以分析binlog.General log.slowlog,也可以通过SHOWPROCESSLIST或者通过tcpdump ...

  9. 3,bool值之间的转换,和str的各个功能属性。

    bool值之间的转换 and 空字符串即为False   字符串内有内容即为True. a = 11 c = str(a) #int转换成str print(type(c)) a = ' b = in ...

  10. luogu2219 [HAOI2007]修筑绿化带

    和「理想的正方形」比较相似,需要先掌握那道题. 花坛外头每一边必须套上绿化带 #include <iostream> #include <cstdio> using names ...