Submission #1159190

#TimeUsernameProblemLanguageResultExecution timeMemory
1159190aligay100infaThe Potion of Great Power (CEOI20_potion)C++20
17 / 100
3030 ms3572 KiB
#include <bits/stdc++.h>

using namespace std;

namespace {
    const int N = 1e5 + 3;
    int n, d, m, h[N], a[N], b[N];
}

void swap(int &a, int &b) {
    a = a ^ b;
    b = a ^ b;
    a = a ^ b;
}

int min(int x, int y) {
    if (x < y) return x;
    return y;
}

int max(int x, int y) {
    if (x > y) return x;
    return y;
}

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

void curseChanges(int U, int A[], int B[]) {
    m = U;
    for (int i = 1; i <= m; i++) {
        a[i] = A[i - 1] + 1;
        b[i] = B[i - 1] + 1;
        if (a[i] > b[i]) swap(a[i], b[i]);
    }
}

int question(int x, int y, int v) {
    x++;
    y++;
    set <int> s, t, act;
    for (int i = 1; i <= v; i++) {
        if (a[i] == y) {
            bool ok = s.find(b[i]) != s.end();
            if (ok) s.erase(b[i]);
            else s.insert(b[i]);
        }
        if (a[i] == x) {
            bool ok = t.find(b[i]) != t.end();
            if (ok) t.erase(b[i]);
            else t.insert(b[i]);
        } 
        if (b[i] == y) {
            bool ok = s.find(a[i]) != s.end();
            if (ok) s.erase(a[i]);
            else s.insert(a[i]);
        }
        if (b[i] == x) {
            bool ok = t.find(a[i]) != t.end();
            if (ok) t.erase(a[i]);
            else t.insert(a[i]);
        } 
    }
    for (int it: s) act.insert(h[it]);
    int ans = 1e9;
    for (int i: t) {
        // cout << x << ' ' << i << '\n';
        auto cur = act.lower_bound(h[i]);
        if (cur != act.end()) ans = min(ans, abs(h[i] - *cur));
        if (cur == act.begin()) continue;
        cur--;
        ans = min(ans, abs(h[i] - *cur));
    }

    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...