Submission #631666

# Submission time Handle Problem Language Result Execution time Memory
631666 2022-08-18T11:59:18 Z abc864197532 The Potion of Great Power (CEOI20_potion) C++17
70 / 100
2305 ms 73220 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}
template <typename T> struct vv : vector <vector <T>> {
    vv(int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {}
    vv() {}
};
template <typename T> struct vvv : vector <vv <T>> {
    vvv(int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {}
    vvv() {}
};
#ifdef Doludu
#define test(args...) abc("[" + string(#args) + "]", args)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(args...) void(0)
#define owo ios::sync_with_stdio(false); cin.tie(0)
#endif
const int mod = 1e9 + 7, N = 200005, logC = 30, K = 450;

vector <pii> tree[N << 1];

void add(int l, int r, int u, int v) {
    for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
        if (l & 1)
            tree[l++].eb(u, v);
        if (r & 1)
            tree[--r].eb(u, v);
    }
}

int u_nei[N], v_nei[N], h[N], sz1, sz2;

void query(int day, int u, int v) {
    sz1 = sz2 = 0;
    for (day += N; day > 0; day >>= 1) {
        for (auto it = lower_bound(all(tree[day]), mp(u, -1)); it != tree[day].end() && it->X == u; ++it) {
            u_nei[sz1++] = h[it->Y];
        }
        for (auto it = lower_bound(all(tree[day]), mp(v, -1)); it != tree[day].end() && it->X == v; ++it) {
            v_nei[sz2++] = h[it->Y];
        }
    }
}

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

void curseChanges(int m, int a[], int b[]) {
    map <pii, int> edge;
    for (int i = 1; i <= m; ++i) {
        int u = a[i - 1], v = b[i - 1];
        if (u > v)
            swap(u, v);
        if (edge.count({u, v})) {
            add(edge[{u, v}], i, u, v);
            add(edge[{u, v}], i, v, u);
            edge.erase({u, v});
        } else {
            edge[{u, v}] = i;
        }
    }
    for (auto A : edge) {
        add(A.Y, m + 1, A.X.X, A.X.Y);
        add(A.Y, m + 1, A.X.Y, A.X.X);
    }
    for (int i = 0; i < N; ++i)
        sort(all(tree[i]));
}

int question(int u, int v, int d) {
    query(d, u, v);
    if (!sz1 || !sz2) {
        return 1000000000;
    } else {
        int ans = 1000000000;
        sort(u_nei, u_nei + sz1), sort(v_nei, v_nei + sz2);
        for (int i = 0, j = 0; i < sz1; ++i) {
            while (j < sz2 && v_nei[j] < u_nei[i])
                j++;
            if (j < sz2)
                ans = min(ans, abs(u_nei[i] - v_nei[j]));
            if (j) 
                ans = min(ans, abs(u_nei[i] - v_nei[j - 1]));
        }
        return ans;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9708 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9936 KB Output is correct
2 Correct 10 ms 9936 KB Output is correct
3 Correct 10 ms 9936 KB Output is correct
4 Correct 22 ms 10692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 825 ms 73220 KB Output is correct
2 Correct 774 ms 73100 KB Output is correct
3 Correct 301 ms 33856 KB Output is correct
4 Correct 1463 ms 60876 KB Output is correct
5 Correct 866 ms 72400 KB Output is correct
6 Correct 2305 ms 54792 KB Output is correct
7 Correct 758 ms 54888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 976 ms 73084 KB Output is correct
2 Correct 923 ms 38284 KB Output is correct
3 Correct 1014 ms 54764 KB Output is correct
4 Correct 1173 ms 54708 KB Output is correct
5 Correct 946 ms 72844 KB Output is correct
6 Correct 1288 ms 54872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 12584 KB Output is correct
2 Correct 105 ms 11108 KB Output is correct
3 Correct 120 ms 10576 KB Output is correct
4 Correct 599 ms 12076 KB Output is correct
5 Correct 598 ms 12268 KB Output is correct
6 Correct 143 ms 12492 KB Output is correct
7 Correct 483 ms 11116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9708 KB Incorrect
2 Halted 0 ms 0 KB -