CF375D-Tree and Queries(莫队+按次数分块)

题目
题意:给出一棵 n 个结点的树,每个结点有一个颜色 c i 。 询问 q 次,每次询问以 v 结点为根的子树中,出现次数 ≥k 的颜色有多少种。树的根节点是1。
数据范围: 2<=n<=1e5 1<=m<=1e5 1<=a[i]<=1e5;

思路:每次询问k值不一样,必须除了莫队还要有一个数据结构维护次数,也要用一个cnt[]数组维护。每次修改很多,查询只有m次。故用分块。
写完20分钟 调试2小时 T_T 一定要思路清晰!!! 要自杀了

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define m(a,b) memset(a,b,sizeof a)
#define foru(i,a,b) for(int i=a;i<=b;++i)
#define en '\n'
using namespace std;
typedef long long ll;
const int N=1e5+5,M=1e5+5;
template<class T>void rd(T &x)
{
   
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9')  {
   f|=(ch=='-');ch=getchar();}
    while(ch>='0'&&ch<='9'){
   x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return;
}
struct Edge{
   int to,nex;}edge[N
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值