General

# Author Problem Lang Verdict Time Memory Sent Judged
12502322 Out of competition:
* rajat1603
570D - 28 GNU C++11 Time limit exceeded on test 30 2000 ms 172100 KB 2015-08-13 20:01:26 2015-08-13 21:37:30

→ 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[26][N];
vector < int > v[N];
int start[N];
int finish[N];
int timer = 0;
void dfs(int node , int depth){
start[node] = ++timer;
levels[str[node] - 'a'][depth].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[i][hi].begin() , levels[i][hi].end() , finish[vi] + 1) - lower_bound(levels[i][hi].begin() , levels[i][hi].end() , start[vi]);
ctr += x;
if(x & 1){
++odd;
}
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
?
?
Checker comment
?
Diagnostics
?
Click to see test details