题解:

更据题意,在树上深度为没一个数的都放在一起,要用的时候二分出来,看结果

用c++的数据结构

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=5e5+,L=;
char s[N];
int n,m,cnt=,max_h=,high[N];
vector<int>E[N],A[N],B[N];
pair<int,int>order[N];
void dfs(int x,int h)
{
max_h=max(h,max_h);
high[x]=h;
order[x].first=++cnt;
A[h].push_back(<<(s[x-]-'a'));
B[h].push_back(cnt);
for (int i=;i<E[x].size();i++)dfs(E[x][i],h+);
order[x].second=cnt;
}
int solve(int x,int h)
{
if (h<=high[x]||!B[h].size())return ;
int l=(int)(lower_bound(B[h].begin(),B[h].end(),
order[x].first)-B[h].begin());
int r=(int)(upper_bound(B[h].begin(),B[h].end(),
order[x].second)-B[h].begin()-);
if (l>r)return ;
int ans=A[h][r]^(l?A[h][l-]:);
if (ans==(ans&(-ans)))return ;
return ;
}
int read()
{
char c=;int x=;
for(;c<''||c>'';c=getchar());
for(;c>=''&&c<='';c=getchar())x=x*+c-'';
return x;
}
int main()
{
n=read();m=read();
for (int i=;i<=n;i++)E[read()].push_back(i);
scanf("%s",&s);
dfs(,);
max_h++;
for (int i=;i<max_h;i++)
for (int j=;j<A[i].size();j++)A[i][j]^=A[i][j-];
while (m--)
{
int v=read(),h=read();
if (solve(v,h-))puts("Yes");
else puts("No");
}
}

51nod1513的更多相关文章

随机推荐

  1. Spark On YARN 分布式集群安装

    一.导读 最近开始学习大数据分析,说到大数据分析,就必须提到Hadoop与Spark.要研究大数据分析,就必须安装这两个软件,特此记录一下安装过程.Hadoop使用V2版本,Hadoop有单机.伪分布 ...

  2. 使用fragment添加底部导航栏

    切记:fragment一定要放在framlayout中,不然不会被替换完全(就是切换之后原来的fagment可能还会存在) main.xml <LinearLayout xmlns:androi ...

  3. Django框架(五) Django之模板语法

    什么是模板 只要是在html里面有模板语法就不是html文件了,这样的文件就叫做模板 模板语法分类 模板语法之变量:语法为 {{ 变量名 }}: 在 Django 模板中遍历复杂数据结构的关键是句点字 ...

  4. 如何替换vi的配色方案

    答: 1.获取配色方案 git clone git://github.com/altercation/vim-colors-solarized.git ~/.vim/bundle/vim-colors ...

  5. Https流程,openssl本地自建证书,抓包

    HTTPS:超文本安全传输协议,和HTTP相比,多了一个SSL/TSL的认证过程,端口为443在http(超文本传输协议)基础上提出的一种安全的http协议,因此可以称为安全的超文本传输协议.http ...

  6. pip 更换国内镜像与记录

    更换pip源到国内镜像 阿里云 http://mirrors.aliyun.com/pypi/simple/   中国科技大学 https://pypi.mirrors.ustc.edu.cn/sim ...

  7. Spyder clear variable explorer from memory

    https://stackoverflow.com/questions/45853595/spyder-clear-variable-explorer-along-with-variables-fro ...

  8. hdu 6444 网络赛 Neko's loop(单调队列 + 裴蜀定理)题解

    题意:有编号为0~n-1的n个游戏,每个活动都有一个价值(可为负),给你m,s和k,你可以从任意一个编号开始玩,但是下一个游戏必须是编号为(i + k)%n的游戏,你最多能玩m次游戏,问你如果最后你手 ...

  9. LOJ #10222. 「一本通 6.5 例 4」佳佳的 Fibonacci

    题目链接 题目大意 $$F[i]=F[i-1]+F[i-2]\ (\ F[1]=1\ ,\ F[2]=1\ )$$ $$T[i]=F[1]+2F[2]+3F[3]+...+nF[n]$$ 求$T[n] ...

  10. LA 3213 古老的密码

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=15& ...