제출 #578096

#제출 시각아이디문제언어결과실행 시간메모리
578096tengiz05The Potion of Great Power (CEOI20_potion)C++17
17 / 100
3089 ms11252 KiB
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif
using namespace std;

constexpr int N = 1E5 + 5, B = 2, D = 2;
int h[N], n;
vector<pair<int, int>> mv[N];

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

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

int question(int x, int y, int v) {
    multiset<int> a, ha;
    multiset<int> b, hb;
    for (int i = 0; i < int(mv[x].size()) && mv[x][i].first < v; i++) {
        int g = mv[x][i].second;
        if (a.count(g)) {
            a.erase(g);
            ha.erase(ha.find(h[g]));
        } else {
            a.insert(g);
            ha.insert(h[g]);
        }
    }
    for (int i = 0; i < int(mv[y].size()) && mv[y][i].first < v; i++) {
        int g = mv[y][i].second;
        if (b.count(g)) {
            b.erase(g);
            hb.erase(hb.find(h[g]));
        } else {
            b.insert(g);
            hb.insert(h[g]);
        }
    }
    vector<int> B(hb.begin(), hb.end());
    int i = 0;
    int ans = 1E9;
    for (auto x : ha) {
        while (i < int(B.size()) && B[i] < x)
            i++;
        if (i > 0) {
            ans = min(ans, x - B[i - 1]);
        }
        if (i < int(B.size())) {
            ans = min(ans, B[i] - x);
        }
    }
    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...