제출 #1207554

#제출 시각아이디문제언어결과실행 시간메모리
1207554trimkusCircle Passing (EGOI24_circlepassing)C++20
42 / 100
497 ms1114112 KiB
#include <bits/stdc++.h>
using namespace std;



int main() {
	int n, m, q;
	cin >> n >> m >> q;
	vector<int> tel;
	for (int i = 0; i < m; ++i) {
		int a;
		cin >> a;
		tel.push_back(a);
		tel.push_back(a + n);
	}
	sort(begin(tel), end(tel));
	vector<int> l(2 * n), r(2 * n);
	for (int i = 0, j = 0; i < 2 * n; ++i) {
		while (j + 1 < (int)tel.size() && tel[j + 1] <= i) j++;
		l[i] = (tel[j] > i ? tel.back() : tel[j]);
	}
	for (int i = 2 * n - 1, j = tel.size() - 1; i >= 0; --i) {
		while (j - 1 >= 0 && tel[j - 1] >= i) j--;
		r[i] = (tel[j] < i ? tel[0] : tel[j]);
	}
	for (int i = 0; i < 2 * n; ++i) {
		//~ cout << l[i] << " " << r[i] << "\n";
	}
	auto calc = [&](int x, int y) -> int {
		//~ cout << x << " " << y << " -> ";
		if (x >= y) swap(x, y);
		//~ cout << x << " " << y << " dist = " << min(abs(y - x), abs(2 * n + x - y)) << endl;
		return min(abs(y - x), abs(2 * n + x - y));
	};
	auto nxt = [&](int x) -> int {
		return (x + n) % (2 * n);
	};
	while (q--) {
		int a, b;
		cin >> a >> b;
		int res = calc(a, b);
		//~ cout << res << " -> ";
		{
			int now = calc(a, l[a]);
			int na = l[a];
			res = min(res, now + calc(na, b));
			//~ cout << res << "= res \n";
			//~ cout << na << " -> ";
			na = nxt(na);
			//~ cout << na << endl;
			//~ cout << now << " = " << na << " = " << calc(na, b) << endl;
			res = min(res, now + 1 + calc(na, b));
		}
		{
			int now = calc(a, r[a]);
			int na = r[a];
			res = min(res, now + calc(na, b));
			na = nxt(na);
			res = min(res, now + 1 + calc(na, b));
		}
		cout << res << "\n";
	}
}
#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...