제출 #1341116

#제출 시각아이디문제언어결과실행 시간메모리
1341116aykhnCircle Passing (EGOI24_circlepassing)C++20
100 / 100
364 ms63192 KiB
#include <bits/stdc++.h>

using namespace std;

#define inf 0x3F3F3F3F3F3F3F3F
#define int long long
#define bpc __builtin_popcountll

int n, m, q;

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

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> q;
	map<int, int> mp;
	for (int i = 0; i < m; i++)
	{
		int x;
		cin >> x;
		mp[x] = x + n, mp[x + n] = x;
	}
	while (q--)
	{
		int x, y, res = inf;
		cin >> x >> y;
		auto it = mp.lower_bound(x);
		if (it != mp.end()) res = min(res, dist(x, (*it).first) + dist((*it).second, y) + 1);
		else if (!mp.empty()) it = mp.begin(), res = min(res, dist(x, (*it).first) + dist((*it).second, y) + 1);
		if (it != mp.begin()) it = prev(it), res = min(res, dist(x, (*it).first) + dist((*it).second, y) + 1);
		else if (!mp.empty()) it = prev(mp.end()), res = min(res, dist(x, (*it).first) + dist((*it).second, y) + 1);
		cout << min(res, dist(x, y)) << '\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...