rt。我用一个明显是 O(ab) 的做法通过了本题。具体的,对于每一个领主,枚举所有感染源到它的距离,最小值即为答案。
但是题目中不是说 a,b≤105 吗?这样的做法为什么还能通过(且单点最大耗时不到 200ms)?
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
int dist(int x, int y, int u, int v) {
return abs(x - u) + abs(y - v);
}
vector<pair<int, int>> p;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> a >> b;
for (int i = 0; i < a; ++i) {
int x, y;
cin >> x >> y;
p.emplace_back(x, y);
}
for (int i = 0; i < b; ++i) {
int x, y;
cin >> x >> y;
int ans = 1e9;
for (auto [u, v]: p) {
ans = min(dist(x, y, u, v), ans);
}
cout << ans << "\n";
}
return 0;
}