제출 #1364745

#제출 시각아이디문제언어결과실행 시간메모리
1364745tuncay_pashaCircle Passing (EGOI24_circlepassing)C++20
31 / 100
313 ms52056 KiB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define pasha ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(v) begin(v), end(v)
using namespace std;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

constexpr int N = 2e+5 + 5, oo = 2e+18;

void _() {
  int n, m, q; cin >> n >> m >> q;
  vector<int> k(m);
  set<int> yes;
  for (int i = 0; i < m; ++i) {
    cin >> k[i];
    yes.insert(k[i]);
    yes.insert(k[i] + n);
  }
  auto dist = [&](int x, int y) -> int {
    return min(abs(y - x), 2 * n - abs(x - y));
  };
  while (q--) {
    int x, y; cin >> x >> y;
    if (yes.find(x) != yes.end()) {
      int ans = dist(x, y);
      ans = min(ans, dist(x + n, y) + 1);
      cout << ans << '\n';
    } else {
      int ans = dist(x, y);
      auto r = yes.lower_bound(x);
      auto l = yes.upper_bound(x);
      if (r == yes.end()) {
        r = yes.begin();
      }
      if (l == yes.begin()) {
        l = --yes.end();
      } else {
        --l;
      }
      int lx = *l;
      int rx = *r;
      ans = min(ans, dist(x, lx) + 1 + dist((lx > n ? lx - n : lx + n), y));
      ans = min(ans, dist(x, rx) + 1 + dist((rx > n ? rx - n : rx + n), y));
      cout << ans << '\n';
      cerr << "debug(lx, rx): " << lx << "; " << rx << '\n';
    }
  }
}

signed main() {
  pasha
  int t = 1;
  // cin >> t;
  for (int cs = 1; cs <= t; ++cs) {
    _();
    // cout << '\n';
  }
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…