Submission #1021925

# Submission time Handle Problem Language Result Execution time Memory
1021925 2024-07-13T07:40:07 Z guagua0407 File Paths (BOI15_fil) C++17
33 / 100
36 ms 604 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int mxn=1e6+5;

int main() {_
    int n,m,k;
    cin>>n>>m>>k;
    int len;
    cin>>len;
    len++;
    vector<ll> pre(n+1);
    vector<int> p(n+1);
    for(int i=1;i<=n;i++){
        int l;
        cin>>p[i]>>l;
        pre[i]=pre[p[i]]+l+1;
    }
    vector<ll> vec(n+1);
    for(int i=0;i<=n;i++){
        vec[i]=pre[i]+len;
    }
    vec.push_back(0);
    sort(all(vec));
    for(int i=0;i<m;i++){
        int pp,l;
        cin>>pp>>l;
        int cur=pre[pp]+l+1;
        bool tf=false;
        while(true){
            ll target=k-(cur-pre[pp]);
            //cout<<target<<'\n';
            int pos=lower_bound(all(vec),target)-vec.begin();
            if(pos!=n+1 and vec[pos]==target){
                tf=true;
            }
            if(tf or pp==0) break;
            pp=p[pp];
        }
        cout<<(tf?"YES":"NO")<<'\n';
    }
    return 0;
}
//maybe its multiset not set
//yeeorz
//laborz

Compilation message

fil.cpp: In function 'void setIO(std::string)':
fil.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fil.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 560 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 36 ms 604 KB Output is correct
6 Correct 27 ms 604 KB Output is correct
7 Correct 19 ms 604 KB Output is correct
8 Correct 19 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 27 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -