답안 #879549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879549 2023-11-27T16:10:31 Z Shayan86 File Paths (BOI15_fil) C++14
100 / 100
223 ms 29284 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define Mp          make_pair
#define sep         ' '
#define endl        '\n'
#define F	        first
#define S	        second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define kill(res)	cout << res << '\n', exit(0);
#define set_dec(x)	cout << fixed << setprecision(x);
#define fast_io     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io     freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll N = 3e3 + 50;
const ll M = 1e6 + 50;
const ll Mod = 1e9 + 7;

int n, m, k, s, par[2*N], h[2*N], cnt[M], res[2*N];

vector<int> adj[2*N], cyc[2*N];

void pre(int v){
    for(int i: cyc[v]) cnt[i]++;
    for(int u: adj[v]) pre(u);

    if(v <= n) for(int i: cyc[v]) cnt[i]--;
    else{
        int dist = k - h[v];
        for(int i = 1; i * i <= dist; i++) if(dist % i == 0) res[v] |= (cnt[i] > 0) | (cnt[dist / i] > 0);
        for(int i: cyc[v]) cnt[i]--;
    }
}

int main(){
    fast_io;

    cin >> n >> m >> k >> s; s++;

    int l;
    for(int i = 1; i <= n+m; i++){
        cin >> par[i] >> l;
        h[i] = h[par[i]] + l + 1;
        adj[par[i]].pb(i);
        if(i > n) res[i] = (h[i] == k);
    }
    par[0] = -1;

    for(int i = 0; i <= n; i++){
        int v = i;
        while(v >= 0){
            if(h[i] - h[v] + s < M) cyc[v].pb(h[i] - h[v] + s);
            v = par[v];
        }
    }

    pre(0);

    vector<int> height;
    for(int i = 0; i <= n; i++) height.pb(h[i]);
    sort(all(height));

    for(int i = n+1; i <= n+m; i++){
        int v = par[i]; l = h[i] - h[par[i]];
        while(v >= 0){
            int dist = k - l - s;
            int idx = lower_bound(all(height), dist) - height.begin();
            if(idx <= n && height[idx] == dist) res[i] = 1;

            if(par[v] >= 0) l += h[v] - h[par[v]];
            v = par[v];
        }
        cout << (res[i] ? "YES\n" : "NO\n");
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4852 KB Output is correct
4 Correct 4 ms 4956 KB Output is correct
5 Correct 4 ms 4700 KB Output is correct
6 Correct 3 ms 4700 KB Output is correct
7 Correct 7 ms 5212 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 3 ms 4996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4956 KB Output is correct
2 Correct 8 ms 5004 KB Output is correct
3 Correct 8 ms 4956 KB Output is correct
4 Correct 8 ms 4956 KB Output is correct
5 Correct 165 ms 24784 KB Output is correct
6 Correct 169 ms 24776 KB Output is correct
7 Correct 83 ms 16224 KB Output is correct
8 Correct 82 ms 16020 KB Output is correct
9 Correct 9 ms 5064 KB Output is correct
10 Correct 7 ms 4956 KB Output is correct
11 Correct 7 ms 5564 KB Output is correct
12 Correct 188 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4852 KB Output is correct
4 Correct 4 ms 4956 KB Output is correct
5 Correct 4 ms 4700 KB Output is correct
6 Correct 3 ms 4700 KB Output is correct
7 Correct 7 ms 5212 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 3 ms 4996 KB Output is correct
13 Correct 8 ms 4956 KB Output is correct
14 Correct 8 ms 5004 KB Output is correct
15 Correct 8 ms 4956 KB Output is correct
16 Correct 8 ms 4956 KB Output is correct
17 Correct 165 ms 24784 KB Output is correct
18 Correct 169 ms 24776 KB Output is correct
19 Correct 83 ms 16224 KB Output is correct
20 Correct 82 ms 16020 KB Output is correct
21 Correct 9 ms 5064 KB Output is correct
22 Correct 7 ms 4956 KB Output is correct
23 Correct 7 ms 5564 KB Output is correct
24 Correct 188 ms 24148 KB Output is correct
25 Correct 7 ms 4956 KB Output is correct
26 Correct 7 ms 4956 KB Output is correct
27 Correct 8 ms 5208 KB Output is correct
28 Correct 7 ms 5004 KB Output is correct
29 Correct 176 ms 24720 KB Output is correct
30 Correct 171 ms 24500 KB Output is correct
31 Correct 82 ms 15992 KB Output is correct
32 Correct 76 ms 15740 KB Output is correct
33 Correct 8 ms 4956 KB Output is correct
34 Correct 6 ms 4996 KB Output is correct
35 Correct 10 ms 5520 KB Output is correct
36 Correct 223 ms 29284 KB Output is correct