Submission #586862

#TimeUsernameProblemLanguageResultExecution timeMemory
586862MohammadAghilFile Paths (BOI15_fil)C++17
0 / 100
24 ms27712 KiB
#include <bits/stdc++.h> // #pragma GCC optimize ("Ofast,unroll-loops") // #pragma GCC target ("avx2") using namespace std; typedef long long ll; typedef pair<int, int> pp; #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl #define per(i,r,l) for(int i = (r); i >= (l); i--) #define rep(i,l,r) for(int i = (l); i < (r); i++) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define pb push_back #define ss second #define ff first void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);} void IOS(){ cin.tie(0) -> sync_with_stdio(0); // #ifndef ONLINE_JUDGE // freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); // #endif } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll mod = 1e9 + 7, maxn = 6e3 + 5, maxk = 1e6 + 5, lg = 22, inf = ll(1e9) + 5; ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;} int l[maxn], par[maxn], n, m, k, s; vector<int> adj[maxn]; int vl[maxk]; bool ans[maxn]; vector<int> dv[maxk]; void add(int u){ int cr = s; while(u + 1){ vl[cr]++; cr += l[u], u = par[u]; } } void del(int u){ int cr = s; while(u + 1){ vl[cr]--; cr += l[u], u = par[u]; } } void dfs(int r, int h = 0){ if(r > n){ int t = k - h; ans[r-n] = t == 0; if(t > 0){ for(int j = 1; j*j <= t; j++){ if(t%j == 0){ if(vl[j] || vl[t/j]){ ans[r-n] = true; break; } } } } }else{ add(r); for(int c: adj[r]) dfs(c, h + l[c]); del(r); } } int main(){ IOS(); // rep(i,1,maxk) for(int j = i; j < maxk; j += i) dv[j].pb(i); par[0] = -1; cin >> n >> m >> k >> s; s++; rep(i,1,n+m+1) cin >> par[i] >> l[i], adj[par[i]].pb(i), l[i]++; dfs(0); rep(i,1,m+1) cout << (ans[i]?"YES\n":"NO\n"); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...