Submission #631658

# Submission time Handle Problem Language Result Execution time Memory
631658 2022-08-18T11:47:00 Z abc864197532 The Potion of Great Power (CEOI20_potion) C++17
Compilation error
0 ms 0 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];
        }
    }
}

int main () {
    owo;
    int n, d, m, q, u, v;
    cin >> n >> d >> m >> q;
    map <pii, int> edge;
    for (int i = 0; i < n; ++i)
        cin >> h[i];
    for (int i = 1; i <= m; ++i) {
        cin >> u >> v;
        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]));
    while (q--) {
        cin >> u >> v >> d;
        query(d, u, v);
        if (!sz1 || !sz2) {
            cout << 1000000000 << endl;
        } 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]));
            }
            cout << ans << endl;
        }
    }
}

Compilation message

/usr/bin/ld: /tmp/ccZ4rRfP.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccnT8yCN.o:potion.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccZ4rRfP.o: in function `main':
grader.cpp:(.text.startup+0xec): undefined reference to `init(int, int, int*)'
/usr/bin/ld: grader.cpp:(.text.startup+0x184): undefined reference to `curseChanges(int, int*, int*)'
/usr/bin/ld: grader.cpp:(.text.startup+0x1d9): undefined reference to `question(int, int, int)'
collect2: error: ld returned 1 exit status