Submission #589860

# Submission time Handle Problem Language Result Execution time Memory
589860 2022-07-05T11:08:19 Z piOOE The Potion of Great Power (CEOI20_potion) C++17
17 / 100
3000 ms 50496 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int maxN = 100000, maxU = 200000, INF = 1000000000;

int a[maxU], b[maxU], h[maxN], n, u, d;

struct comp {
    bool operator() (int i, int j) const {
        return (h[i] == h[j] ? i < j : h[i] < h[j]);
    }
};

vector<set<int, comp>> g[maxN];

set<int, comp> temp[maxN];

vector<int> ti[maxN];
vector<pair<int, int>> c[maxN];

void init(int N, int D, int H[]) {
    n = N, d = D;
    memcpy(h, H, sizeof(h[0]) * n);
}

void curseChanges(int U, int A[], int B[]) {
    u = U;
    memcpy(a, A, sizeof(a[0]) * u), memcpy(b, B, sizeof(b[0]) * u);
    set<pair<int, int>> adj;
    for (int i = 0; i < u; ++i) {
        if (a[i] > b[i]) {
            swap(a[i], b[i]);
        }
        if (adj.count({a[i], b[i]})) {
            adj.erase({a[i], b[i]});
            c[a[i]].emplace_back(~b[i], i + 1);
            c[b[i]].emplace_back(~a[i], i + 1);
            temp[a[i]].erase(b[i]);
            temp[b[i]].erase(a[i]);
        } else {
            adj.insert({a[i], b[i]});
            c[a[i]].emplace_back(b[i], i + 1);
            c[b[i]].emplace_back(a[i], i + 1);
            temp[a[i]].insert(b[i]);
            temp[b[i]].insert(a[i]);
        }
        if (c[a[i]].size() % d == 0) {
            g[a[i]].push_back(temp[a[i]]);
            ti[a[i]].push_back(i + 1);
        }

        if (c[a[i]].size() % d == 0) {
            g[b[i]].push_back(temp[b[i]]);
            ti[b[i]].push_back(i + 1);
        }
    }
}

set<int, comp> get(int x, int v) {
    int it = upper_bound(ti[x].begin(), ti[x].end(), v) - ti[x].begin() - 1, t = 0;
    set<int, comp> ans;
    if (it > -1) {
        ans = g[x][it];
        t = ti[x][it] + 1;
    }
    it = lower_bound(c[x].begin(), c[x].end(), make_pair(-1, t), [](pair<int, int> a, pair<int, int> b) {
        return a.second < b.second;
    }) - c[x].begin();
    for (; it < int(c[x].size()) && c[x][it].second <= v; ++it) {
        auto [y, tt] = c[x][it];
        if (y < 0) {
            ans.erase(~y);
        } else {
            ans.insert(y);
        }
    }
    return ans;
}

int question(int x, int y, int v) {
    int ans = INF;
    set<int, comp> f = get(x, v), s = get(y, v);
    for (int to : f) {
        auto it = s.lower_bound(to);
        if (it != s.end()) {
            ans = min(ans, h[*it] - h[to]);
        }
        if (it != s.begin()) {
            ans = min(ans, h[to] - h[*prev(it)]);
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12240 KB Output is correct
2 Correct 12 ms 12220 KB Output is correct
3 Correct 11 ms 12220 KB Output is correct
4 Correct 30 ms 12960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 642 ms 50488 KB Output is correct
2 Correct 674 ms 50420 KB Output is correct
3 Execution timed out 3083 ms 20020 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 630 ms 50496 KB Output is correct
2 Execution timed out 3023 ms 24636 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 13956 KB Output is correct
2 Correct 255 ms 12600 KB Output is correct
3 Correct 1984 ms 12456 KB Output is correct
4 Execution timed out 3062 ms 13220 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11984 KB Output is correct
2 Correct 9 ms 12240 KB Output is correct
3 Correct 12 ms 12220 KB Output is correct
4 Correct 11 ms 12220 KB Output is correct
5 Correct 30 ms 12960 KB Output is correct
6 Correct 642 ms 50488 KB Output is correct
7 Correct 674 ms 50420 KB Output is correct
8 Execution timed out 3083 ms 20020 KB Time limit exceeded
9 Halted 0 ms 0 KB -