제출 #1171214

#제출 시각아이디문제언어결과실행 시간메모리
1171214cokeaholicCircle Passing (EGOI24_circlepassing)C++20
31 / 100
268 ms47432 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, q;
    cin >> n >> m >> q;
    set<int> bt;
    for (int i = 0; i < m; i++) {
        int b;
        cin >> b;
        bt.insert(b);
        bt.insert(b + n);
    }

    while (q--) {
        int x, y;
        cin >> x >> y;
        if (x > y) swap(x, y);
        int ans = y - x;
        ans = min(ans, 2 * n - y + x);
        auto it = bt.lower_bound(x);
        auto prev_it = it;
        if (it == bt.begin()) {
            prev_it = bt.end();
            prev_it--;
        } else if (it == bt.end()){
            cout << ans << "\n";
            continue;
        } else {
            prev_it--;
        }

        if (*it <= n && *prev_it < n) {
            int c1 = (*it - x) + 1 + abs((*it + n) - y);
            int c2 = (x - *prev_it) + 1 + abs((*prev_it + n) - y);
            ans = min(ans, min(c1, c2));
        } else if (*it <= n && (*prev_it >= n && *prev_it < 2 * n)) {
            int c1 = (*it - x) + 1 + abs((*it + n) - y);
            int c2 = (x + (2 * n - *prev_it)) + 1 + abs((*prev_it - n) - y);
            ans = min(ans, min(c1, c2));
        } else if ((*it > n && *it < 2 * n) && (*prev_it >= n && *prev_it < 2 * n)) {
            int c1 = (*it - x) + 1 + abs((*it - n) - y);
            int c2 = (x - *prev_it) + 1 + abs((*prev_it - n) - y);
            ans = min(ans, min(c1, c2));
        } else if ((*it > n && *it < 2 * n) && (*prev_it < n)) {
            int c1 = (*it - x) + 1 + abs((*it - n) - y);
            int c2 = (x - *prev_it) + 1 + abs((*prev_it + n) - y);
            ans = min(ans, min(c1, c2));
        }

        cout << ans << "\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...