General

# Author Problem Lang Verdict Time Memory Sent Judged
12523900 Practice:
rajat1603
570D - 28 GNU C++11 Accepted 1856 ms 202084 KB 2015-08-14 09:10:33 2015-08-14 09:10:32

→ Source
#include "bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;
int n , q;
int inp;
char str[N] = {NULL};
int vi , hi;
vector < int > levels[N][26];
vector < int > v[N];
int start[N];
int finish[N];
int timer = 0;
void dfs(int node , int depth){
start[node] = ++timer;
levels[depth][str[node] - 'a'].emplace_back(timer);
for(int next : v[node]){
dfs(next , depth + 1);
}
finish[node] = timer;
}
int main(){
scanf("%d %d" , &n , &q);
for(int i = 2 ; i <= n ; ++i){
scanf("%d" , &inp);
v[inp].emplace_back(i);
}
scanf("%s" , str + 1);
dfs(1 , 1);
while(q--){
scanf("%d %d" , &vi , &hi);
int ctr = 0;
int odd = 0;
int even = 0;
for(int i = 0 ; i < 26 ; ++i){
int x = lower_bound(levels[hi][i].begin() , levels[hi][i].end() , finish[vi] + 1) - lower_bound(levels[hi][i].begin() , levels[hi][i].end() , start[vi]);
ctr += x;
if(x & 1){
++odd;
if(odd > 1){
break;
}
}
else{
++even;
}
}
if(ctr & 1){
if(odd == 1){
printf("Yes\n");
}
else{
printf("No\n");
}
}
else{
if(odd == 0){
printf("Yes\n");
}
else{
printf("No\n");
}
}
}
}

?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
?
?
?