Submission #589962

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

using namespace std;

using ll = long long;

const int maxN = 100000, maxU = 200000, INF = 1000000000, BL = 200;
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];
    }
};

template<typename T>
using uset = set<T, comp>;

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

        if (c[b[i]].size() % BL == 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();
    int cnt = 0;
    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);
        }
        cnt += 1;
    }
    assert(cnt <= BL);
    vector<int> answer(ans.begin(), ans.end());
    return answer;
}

int question(int x, int y, int v) {
    int ans = INF;
    vector<int> f = get(x, v), s = get(y, v);
    int pnt = 0;
    for (int to: f) {
        while (pnt < s.size() && h[s[pnt]] < h[to]) {
            pnt += 1;
        }
        if (pnt != s.size()) {
            ans = min(ans, h[s[pnt]] - h[to]);
        }
        if (pnt > 0) {
            ans = min(ans, h[to] - h[s[pnt - 1]]);
        }
    }
    return ans;
}

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:94:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         while (pnt < s.size() && h[s[pnt]] < h[to]) {
      |                ~~~~^~~~~~~~~~
potion.cpp:97:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |         if (pnt != s.size()) {
      |             ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12240 KB Output is correct
2 Correct 10 ms 12172 KB Output is correct
3 Correct 8 ms 12172 KB Output is correct
4 Correct 25 ms 12940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 566 ms 50508 KB Output is correct
2 Correct 586 ms 50396 KB Output is correct
3 Correct 906 ms 20472 KB Output is correct
4 Correct 2923 ms 44568 KB Output is correct
5 Correct 1033 ms 48632 KB Output is correct
6 Execution timed out 3015 ms 45944 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 521 ms 50416 KB Output is correct
2 Execution timed out 3094 ms 39404 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 14004 KB Output is correct
2 Correct 243 ms 12556 KB Output is correct
3 Correct 790 ms 12456 KB Output is correct
4 Correct 1698 ms 13624 KB Output is correct
5 Correct 1682 ms 14052 KB Output is correct
6 Correct 177 ms 13776 KB Output is correct
7 Correct 1713 ms 12968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12032 KB Output is correct
2 Correct 9 ms 12240 KB Output is correct
3 Correct 10 ms 12172 KB Output is correct
4 Correct 8 ms 12172 KB Output is correct
5 Correct 25 ms 12940 KB Output is correct
6 Correct 566 ms 50508 KB Output is correct
7 Correct 586 ms 50396 KB Output is correct
8 Correct 906 ms 20472 KB Output is correct
9 Correct 2923 ms 44568 KB Output is correct
10 Correct 1033 ms 48632 KB Output is correct
11 Execution timed out 3015 ms 45944 KB Time limit exceeded
12 Halted 0 ms 0 KB -