제출 #798724

#제출 시각아이디문제언어결과실행 시간메모리
798724PoonYaPatThe Potion of Great Power (CEOI20_potion)C++14
17 / 100
532 ms262144 KiB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,vector<int>> piv;

int n,h[100005];
vector<piv> v[100005];

void add(int x, int y, int t) { //add y to x
    vector<int> temp;
    if (find(v[x].back().second.begin(),v[x].back().second.end(),y)==v[x].back().second.end()) {
        bool f=false;
        for (auto s : v[x].back().second) {
            if (h[s]<h[y]) temp.push_back(s);
            else {
                if (!f) {
                    temp.push_back(y);
                    temp.push_back(s);
                    f=true;
                } else {
                    temp.push_back(s);
                }
            }
        }
        if (!f) temp.push_back(y);
    } else {
        for (auto s : v[x].back().second) {
            if (s!=y) temp.push_back(s);
        }
    }

    v[x].push_back(piv(t,temp));
}

void init(int N, int D, int H[]) {
    n=N;
    for (int i=0; i<n; ++i) h[i]=H[i], v[i].push_back(piv(0,{}));
}

void curseChanges(int U, int A[], int B[]) {
    for (int i=0; i<U; ++i) {
        add(A[i],B[i],i+1);
        add(B[i],A[i],i+1);
    }
}

int question(int x, int y, int day) {
    int hx=upper_bound(v[x].begin(),v[x].end(),piv(day+1,{}))-v[x].begin()-1;
    int hy=upper_bound(v[y].begin(),v[y].end(),piv(day+1,{}))-v[y].begin()-1;
    int xi=0, yi=0, nx=v[x][hx].second.size(), ny=v[y][hy].second.size();

    if (!nx || !ny) return 1e9;
    else {
        int ans=INT_MAX;
        while (xi<nx && yi<ny) {
            ans=min(ans,abs(h[v[x][hx].second[xi]]-h[v[y][hy].second[yi]]));
            if (h[v[x][hx].second[xi]]>h[v[y][hy].second[yi]]) ++yi;
            else ++xi;
        }
        return ans;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...