| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1147484 | zakimoi | Circle Passing (EGOI24_circlepassing) | C++20 | 161 ms | 8696 KiB | 
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <set>
#include <unordered_map>
#define int long long int
using namespace std;
int MAX = 1e9 + 7;
void iO() {
    freopen("output.txt","w",stdout);
    freopen("input.txt","r",stdin);
}
int32_t main () {
    // iO();
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> bestie;
    for (int i = 0; i < m; i++) {
        int temp;
        cin >> temp;
        bestie.push_back(temp);
        bestie.push_back(temp + n);
    }
    sort(bestie.begin(), bestie.end());
    for (int i_ = 0; i_ < q; i_++) {
        int begin, end;
        cin >> begin >> end;
        int notp = abs(end - begin);
        notp = min(notp, 2*n - notp);
        int lower_index = lower_bound(bestie.begin(), bestie.end(), begin) - bestie.begin();
        int lower = bestie[lower_index];
        int bigger = bestie[(lower_index - 1 + 2*m) % (2*m)];
        //cout << "gyatt " << lower_index << ' ' << (lower_index - 1 + 2*m) % (2*m) << endl;
        int closest_lower = abs(lower - begin);
        closest_lower = min(closest_lower, 2*n - closest_lower) + 1;
        int closest_bigger = abs(bigger - begin);
        closest_bigger = min(closest_bigger, 2*n - closest_bigger) + 1;
        int lower2end = abs(((lower + n) % (2*n))  - end);
        lower2end = min(lower2end, 2*n - lower2end);
        int bigger2end = abs(((bigger + n) % (2*n)) - end);
        bigger2end = min(bigger2end, 2*n - bigger2end);
        int closestp = min(closest_bigger + bigger2end, closest_lower + lower2end);
        cout << min(notp, closestp) << endl;
    }
}
// 1 1 2 5 7
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
