#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;
const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 1000010, LOG=20;
int n, m, k, s, u, v, x, y, t, a, b;
int L[MAXN], P[MAXN];
int cnt[MAXN];
bool ans[MAXN];
vector<int> G[MAXN];
vector<int> D[MAXN];
vector<pii> query[MAXN];
vector<int> vec;
void shit(int x){
vec.clear();
for (int i=1; i*i<=x; i++) if (x%i==0){
vec.pb(i);
vec.pb(x/i);
}
}
void dfs(int node){
for (int tmp=node; ; tmp=P[tmp]){
cnt[min(MAXN-1, P[node]-P[tmp]+s)]++;
if (!tmp) break ;
}
//debug(node)
for (pii p:query[node]){
//debugp(p)
shit(p.first);
for (int d:vec) ans[p.second]|=(cnt[d]>0);
}
for (int v:G[node]) dfs(v);
for (int tmp=node; ; tmp=P[tmp]){
cnt[min(MAXN-1, P[node]-P[tmp]+s)]--;
if (!tmp) break ;
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//for (int i=1; i<MAXN; i++) for (int j=i; j<MAXN; j+=i) D[j].pb(i);
cin>>n>>m>>k>>s;
s++;
for (int i=1; i<=n; i++){
cin>>P[i]>>L[i];
G[P[i]].pb(i);
L[i]+=L[P[i]]+1;
//debug2(i, L[i])
}
for (int i=1; i<=m; i++){
cin>>x>>y;
y+=L[x]+1;
//debug(y)
if (y==k) ans[i]=1;
if (y>=k) continue ;
query[x].pb({k-y, i});
}
dfs(0);
for (int i=1; i<=m; i++){
if (ans[i]) cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}
/*
2 4 22
2
0 1
1 5
2 13
2 10
1 4
0 7
2 1 22
2
0 1
1 5
2 13
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
70752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
72 ms |
70940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
70752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |