51nod1513
题解:
更据题意,在树上深度为没一个数的都放在一起,要用的时候二分出来,看结果
用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的更多相关文章
随机推荐
- Python3基础 __setattr__ 在属性被赋值的时候,新增提示功能
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- C#中dll附加配置文件
DLL-with-configuration-file带配置文件的dll http://www.codeproject.com/Tips/199441/DLL-with-configuration-f ...
- sql 之优化小技巧
SET NOCOUNT ON:不返回计数,如果存储过程中包含一些并不返回实际数据的语句,网络通信流量便会大量减少,可以显著提高应用程序性能:
- BZOJ1966: [Ahoi2005]VIRUS 病毒检测 Trie+搜索
Description 科学家们在Samuel星球上的探险仍在继续.非常幸运的,在Samuel星球的南极附近,探险机器人发现了一个巨大的冰湖!机器人在这个冰湖中搜集到了许多RNA片段运回了实验基地.科 ...
- C#学习笔记(四):switch语句
条件语句 switch语句快速生成枚举方法,复制枚举名在switch()里,双击TAB 快速生成方法,用纠错功能 随机数 using System; using System.Collections. ...
- MVC ---- Lambda表达式
Lambda表达式是比匿名函数还简洁的一种匿名方法语法 Lambda表达式缩写推演 new Func<string,int>(delegate(string str){return str ...
- bzoj 1832 lca
1832: [AHOI2008]聚会 Time Limit: 10 Sec Memory Limit: 64 MB Description Y岛风景美丽宜人,气候温和,物产丰富.Y岛上有N个城市,有 ...
- python 重复元素排序
def counting_sort(array1, max_val): m = max_val + count = [] * m for a in array1: # count occurences ...
- Jmeter工具做性能测试 常见的错误汇总
在Win机器上用Jmeter做性能测试,汇总下我自身遇到的错误和解决方案 java.net.BindException: Address already in use: JVM_Bind 原因分析:压 ...
- gulp4小demo
本来想着用gulp搭建一个自动化构建工具,结果一顿报错,后来发现我重新安装的gulp版本是4.0.0,与3版本还是不太一样的,遂记之. Gulp 3版本Demo: const gulp = requi ...