Submission #589911

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

using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

using ll = long long;
template<typename T>
using uset = unordered_set<T, custom_hash>;

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

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

vector<uset<int>> g[maxN];

uset<int> 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() % 50 == 0) {
            g[a[i]].push_back(temp[a[i]]);
            ti[a[i]].push_back(i + 1);
        }

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

vector<int> get(int x, int v) {
    int it = upper_bound(ti[x].begin(), ti[x].end(), v) - ti[x].begin() - 1, t = 0;
    uset<int> 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);
        }
    }
    vector<int> answer;
    for (int y: ans) {
        answer.push_back(y);
    }
    return answer;
}

int question(int x, int y, int v) {
    int ans = INF;
    vector<int> f = get(x, v), s = get(y, v);
    sort(s.begin(), s.end(), [](int i, int j) {
        return h[i] == h[j] ? i < j : h[i] < h[j];
    });
    for (int to: f) {
        auto it = lower_bound(s.begin(), s.end(), to, [](int i, int j) {
            return h[i] == h[j] ? i < j : h[i] < h[j];
        });
        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 6 ms 12752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 13008 KB Output is correct
2 Correct 8 ms 13008 KB Output is correct
3 Correct 9 ms 13008 KB Output is correct
4 Correct 20 ms 13980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 562 ms 54984 KB Output is correct
2 Correct 544 ms 54988 KB Output is correct
3 Correct 410 ms 25152 KB Output is correct
4 Execution timed out 3075 ms 76204 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 534 ms 54960 KB Output is correct
2 Execution timed out 3028 ms 91356 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 15440 KB Output is correct
2 Correct 211 ms 13520 KB Output is correct
3 Correct 340 ms 13520 KB Output is correct
4 Correct 1847 ms 15760 KB Output is correct
5 Correct 1683 ms 16080 KB Output is correct
6 Correct 217 ms 14472 KB Output is correct
7 Correct 1324 ms 14616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12752 KB Output is correct
2 Correct 10 ms 13008 KB Output is correct
3 Correct 8 ms 13008 KB Output is correct
4 Correct 9 ms 13008 KB Output is correct
5 Correct 20 ms 13980 KB Output is correct
6 Correct 562 ms 54984 KB Output is correct
7 Correct 544 ms 54988 KB Output is correct
8 Correct 410 ms 25152 KB Output is correct
9 Execution timed out 3075 ms 76204 KB Time limit exceeded
10 Halted 0 ms 0 KB -