Submission #1347525

#TimeUsernameProblemLanguageResultExecution timeMemory
1347525julia_08Circle Passing (EGOI24_circlepassing)C++20
0 / 100
2 ms580 KiB
#include <bits/stdc++.h>
using namespace std;

int n;

int dist(int x, int y){
  if(x > y) swap(x, y);
  return min(y - x, 2 * n - (y - x));
}

int main(){
  cin.tie(0)->sync_with_stdio(0);

  int m, q; cin >> n >> m >> q;

  set<int> s;

  while(m--){

    int k; cin >> k;
    
    s.insert(k);
    // s.insert(k + n);
  
  }

  while(q--){
  
    int x, y; cin >> x >> y;
    if(x > y) swap(x, y);

    int ans = dist(x, y);

    if(y > n){

      if(*s.begin() <= y - n) ans = min(ans, y + 1 - n);
      if(*s.rbegin() >= y - n) ans = min(ans, 2 * (*s.lower_bound(y - n)) + n + 1 - y);

    } else{

      if(*s.rbegin() >= y) ans = min(ans, n - y + 1);
      if(*s.begin() <= y) ans = min(ans, y + n + 1 - 2 * (*--s.upper_bound(y)));

    }

    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...