mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-09 23:58:48 +00:00
P2906 [USACO08OPEN]Cow Neighborhoods G
https://www.luogu.com.cn/record/77072894
This commit is contained in:
parent
b6e2f3357b
commit
81b03a11c8
62
Luogu/P2906/P2906.cpp
Normal file
62
Luogu/P2906/P2906.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 1e5 + 5;
|
||||||
|
|
||||||
|
int n, c, fa[N], cnt[N], ans, max;
|
||||||
|
std::pair<int, int> points[N];
|
||||||
|
std::set<std::pair<int, int>> set;
|
||||||
|
|
||||||
|
int find(int x) {
|
||||||
|
return fa[x] == x ? x : fa[x] = find(fa[x]);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void merge(int x, int y) {
|
||||||
|
fa[find(x)] = find(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> c;
|
||||||
|
|
||||||
|
for (int i = 1, x, y; i <= n; i++) {
|
||||||
|
cin >> x >> y;
|
||||||
|
|
||||||
|
points[i] = std::make_pair(x + y, x - y);
|
||||||
|
fa[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(points + 1, points + 1 + n);
|
||||||
|
|
||||||
|
set.insert(std::make_pair(points[1].second, 1));
|
||||||
|
for (int i = 2, l = 1; i <= n; i++) {
|
||||||
|
while (points[i].first - points[l].first > c) {
|
||||||
|
set.erase(std::make_pair(points[l].second, l));
|
||||||
|
l++;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = set.lower_bound(std::make_pair(points[i].second, 0));
|
||||||
|
|
||||||
|
if (it != set.end() && it->first - points[i].second <= c) merge(i, it->second);
|
||||||
|
if (it != set.begin() && points[i].second - (--it)->first <= c) merge(i, it->second);
|
||||||
|
|
||||||
|
set.insert(std::make_pair(points[i].second, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
if (find(i) == i) ans++;
|
||||||
|
|
||||||
|
max = std::max(max, ++cnt[find(i)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << ans << ' ' << max << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
Luogu/P2906/data/nabor.1.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.1.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.10.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.10.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.11.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.11.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.12.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.12.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.13.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.13.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.14.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.14.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.15.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.15.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.2.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.2.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.3.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.3.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.4.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.4.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.5.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.5.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.6.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.6.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.7.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.7.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.8.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.8.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.9.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P2906/data/nabor.9.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P2906/data/nabor.9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user