题解:

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

用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. Node10.15.0的安装

    1. 首先我们需要去node官网下载最近版本的压缩包,然后我们把他们解压到我们自定义的安装路径,我使用的是/usr/local/lib/nodejs VERSION=v10.15.0 DISTRO=l ...

  2. BZOJ3942: [Usaco2015 Feb]Censoring 栈+KMP

    Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...

  3. CodeForces 1029E div3

    题目链接 第一道场上自己做出来的E题...虽然是div3,而且是原题... 当时做完ABC,D题没有思路就去怼E了,然后发现貌似原题? 事实上就是原题... 给个原题链接... [HNOI2003]消 ...

  4. LLDP协议、STP协议 笔记

    参考: 数据链路层学习之LLDP 生成树协议 LLDP协议.STP协议 笔记 LLDP 提出背景: 随着网络技术的发展,接入网络的设备的种类越来越多,配置越来越复杂,来自不同设备厂商的设备也往往会增加 ...

  5. 安装cartographer_ros

    这里使用的是hitcm(张明明)的github地址,由于google官方的教程需要FQ下载一些文件,因此容易失败,经验证hitcm(张明明)对原文件进行了少许修改后可以成功安装,在他的修改中核心代码不 ...

  6. Xcode集成POD教程

    http://www.cocoachina.com/ios/20150410/11526.html COCOAPODS的网站上有很多非常好用的资源,这里来说一下如何把POD集成到我们的Xcode项目中 ...

  7. Spring AMQP 源码分析 06 - 手动消息确认

    ### 准备 ## 目标 了解 Spring AMQP 如何手动确认消息已成功消费 ## 前置知识 <Spring AMQP 源码分析 04 - MessageListener> ## 相 ...

  8. es5,es6,typescript,nodejs

    es5新特性 讲到js必讲的几个概念,作用域,闭包,IIFE自执行函数 es5主要是对Object,Array,Function做了扩展,还有josn工具 es6新特性 增加了新的数据类型 WeakM ...

  9. C#中简单的文件操作实例

    using System; using System.IO; namespace Demo { class Program { static string tmpPath = @"D:/Lg ...

  10. Unity + NGUI 实现人物头顶UI的信息展示

    1.思路: (1)信息数据:需要展示属性信息 (2)信息的展示:负责显示UI属性信息 (3)UI的跟随:负责实现UI对人物的跟随 (4)UI的管理:负责对UI进行创建于回收,游戏中需要用到UI的地方都 ...