题解:CF1979E Manhattan Triangle
Solution
先转切比雪夫。
讨论取到
考虑两个取
设
钦定
代码比较短。
Code
#include <bits/stdc++.h>
#define REP(i, l, r) for (int i = (l); i <= (r); ++ i)
#define DEP(i, r, l) for (int i = (r); i >= (l); -- i)
#define fi first
#define se second
#define pb emplace_back
#define mems(x, v) memset((x), (v), sizeof(x))
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
using namespace std;
namespace Milkcat {
typedef long long LL;
typedef pair<LL, LL> pii;
const int N = 1e6 + 5;
int n, d, x, y, A, B, C, a[N], b[N];
map<int, set<int>> mp; map<pii, int> id;
int main() {
cin >> n >> d, A = B = C = 0;
REP(i, 1, n) {
cin >> x >> y;
a[i] = x + y, b[i] = x - y;
}
REP(t, 0, 3) {
int dx = (t & 1 ? -d : d);
REP(i, 1, n)
mp[a[i]].insert(b[i]), id[{a[i], b[i]}] = i;
for (auto &[x, s] : mp) {
if (!mp.count(x + dx)) continue;
auto &t = mp[x + dx];
for (int y : s) {
if (!s.count(y + d)) continue;
auto it = t.lower_bound(y);
if (it == t.end() || *it > y + d) continue;
A = id[{x, y}], B = id[{x, y + d}], C = id[{x + dx, *it}]; break;
}
}
mp.clear(), id.clear();
if (A > 0) break;
if (t == 1) REP(i, 1, n) swap(a[i], b[i]);
}
cout << A << ' ' << B << ' ' << C << '\n';
return 0;
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int T = 1; cin >> T;
while (T --) Milkcat::main();
return 0;
}