QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#139370 | #4423. AMPPZ in the times of disease | ckiseki | AC ✓ | 6224ms | 62988kb | C++20 | 2.6kb | 2023-08-13 05:16:48 | 2023-08-13 05:16:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
class DSU {
vector<int> a;
public:
DSU(int n) : a(n) {
iota(a.begin(), a.end(), 0);
}
int query(int x) {
if (a[x] != x)
a[x] = query(a[x]);
return a[x];
}
void merge(int x, int y) {
a[query(x)] = query(y);
}
};
using llf = long double;
struct P {
int64_t x, y;
};
llf dis(P a, P b) {
int64_t dx = a.x - b.x;
int64_t dy = a.y - b.y;
return sqrt(llf(dx * dx + dy * dy));
}
int64_t dis2(P a, P b) {
int64_t dx = a.x - b.x;
int64_t dy = a.y - b.y;
return dx * dx + dy * dy;
}
pair<int, int> closest(const vector<P> &a) {
int64_t d = dis2(a[0], a[1]);
pair<int, int> ans = {0, 1};
for (int i = 0; i < int(a.size()); ++i) {
for (int j = i + 1; j < int(a.size()); ++j) {
auto cur = pair{i, j};
int64_t curd = dis2(a[i], a[j]);
if (curd < d) {
ans = cur;
d = curd;
}
}
}
return ans;
// struct cmp_y {
// bool operator()(const pair<P, int> &p, const pair<P, int> &q) const {
// return tie(p.first.y, p.second) < tie(q.first.y, q.second);
// }
// };
// set<pair<P, int>, cmp_y> s;
// pair<int, int> ans = {0, 1};
// vector<int> o(a.size());
// iota(o.begin(), o.end(), 0);
// sort(o.begin(), o.end(), [&](int p, int q) {
// return tie(a[p].x, a[p].y) < tie(a[q].x, a[q].y);
// });
// llf d = 1e100; int pt = 0;
// for (int i = 0; i < int(a.size()); ++i) {
// while (pt < i and a[o[i]].x - a[o[pt]].x >= d) {
// s.erase({a[o[pt]], o[pt]});
// pt += 1;
// }
// auto it = s.lower_bound({P(a[o[i]].x, a[o[i]].y - d), -1});
// while (it != s.end() and it->first.y - a[o[i]].y < d) {
// llf curd = dis(it->first, a[o[i]]);
// if (curd < d) {
// ans = {it->second, o[i]};
// d = curd;
// }
// it++;
// }
// s.emplace(a[o[i]], o[i]);
// }
// return ans;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<P> a(n);
for (auto &[x, y] : a)
cin >> x >> y;
DSU dsu(n);
unordered_set<int> s;
for (int i = 0; i < k; ++i)
s.insert(i);
for (int i = k; i < n; ++i) {
vector<int> v;
vector<P> que;
s.insert(i);
for (auto si : s) {
v.push_back(si);
que.push_back(a[si]);
}
auto [x, y] = closest(que);
dsu.merge(v[x], v[y]);
s.erase(v[x]);
s.erase(v[y]);
s.insert(v[x]);
}
vector<int> ans(n);
for (int i = 0; i < n; ++i)
if (dsu.query(i) == i)
ans[i] = k--;
for (int i = 0; i < n; ++i)
cout << ans[dsu.query(i)] << " \n"[i + 1 == n];
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6123ms
memory: 6112kb
input:
100 100000 20 270505 510725 245104 76414 131477 992924 781607 895592 562469 622976 564354 637966 980036 112090 522903 687218 113871 977855 6615 123673 13847 347618 657794 165707 420561 183995 11367 136391 507836 694877 985069 105115 774110 486921 14319 338715 774937 118145 981468 99089 803866 491315...
output:
5 8 13 9 10 10 17 11 13 12 19 1 2 12 11 17 18 19 3 17 18 1 7 9 6 5 2 16 7 10 8 1 14 6 16 9 3 2 9 14 14 19 8 5 10 7 5 15 18 15 7 15 1 7 7 4 12 5 12 7 7 3 4 19 9 2 3 16 6 3 14 1 16 6 12 1 3 18 4 20 9 17 13 18 13 19 2 6 15 18 8 10 10 7 7 9 18 6 17 7 18 5 12 5 12 7 12 2 3 18 6 14 7 6 11 15 10 7 11 11 8 ...
result:
ok ac (100 test cases)
Test #2:
score: 0
Accepted
time: 6224ms
memory: 55032kb
input:
5 2000000 20 128546949 27937564 245921588 62819439 245938747 62819439 245920165 62819440 245940996 62819441 245919462 62819441 245943717 62819443 245945427 62819445 245947161 62819447 245947035 62819447 245913847 62819447 245911321 62819450 245910715 62819451 245908052 62819455 245953333 62819457 24...
output:
20 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 ...
result:
ok ac (5 test cases)
Test #3:
score: 0
Accepted
time: 6060ms
memory: 55052kb
input:
5 2000000 20 938915 14534 939099 14534 938896 14534 938968 14534 939120 14534 938967 14534 939092 14534 939047 14534 939083 14534 938959 14534 938980 14534 939094 14534 939096 14534 939158 14534 939129 14534 939050 14534 939146 14534 939067 14534 938953 14534 939118 14534 939174 14534 938957 14534 9...
output:
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
result:
ok ac (5 test cases)
Test #4:
score: 0
Accepted
time: 6177ms
memory: 51544kb
input:
5 1999992 20 714274 363953 4097901 6999896 4285652 7069412 672239 571422 408343 714278 4285652 6512757 995296 428566 4066535 6571329 4285652 6503633 4428508 7305200 1502570 714278 350759 714278 4078994 6999896 4285652 6566018 882958 428566 411620 714278 4085106 6999896 4285652 6530080 4142796 684433...
output:
6 8 11 4 13 7 1 2 7 5 10 13 8 7 1 13 8 7 3 10 5 9 2 5 11 11 9 8 10 12 2 1 9 4 11 9 12 12 11 4 13 10 2 7 3 2 12 4 8 4 13 7 1 12 6 2 7 7 2 4 1 11 4 5 2 3 12 10 12 2 13 10 7 2 5 4 10 9 1 9 14 11 4 14 8 6 2 10 1 7 8 10 13 12 5 7 12 7 13 10 3 10 4 2 9 11 7 8 9 9 13 10 14 12 14 4 2 9 12 1 10 10 7 14 4 3 1...
result:
ok ac (5 test cases)
Test #5:
score: 0
Accepted
time: 5542ms
memory: 3552kb
input:
98934 43 19 139544 85155 814904 5788 529650 268672 283948 536120 269963 210844 141436 82366 83187 749015 517204 336252 313961 432803 609446 700082 75325 746905 269976 218742 262201 982244 267097 970940 240151 822124 603197 913571 245406 817164 136898 78897 540853 274671 509382 335902 911470 765473 1...
output:
10 19 9 18 13 10 14 17 16 15 14 13 12 12 11 2 11 10 9 17 3 10 2 9 8 17 7 15 6 7 15 2 7 6 13 5 4 3 2 13 1 2 16 19 18 14 13 17 16 15 14 13 15 12 6 11 5 19 1 10 15 10 1 18 16 1 7 5 15 19 3 6 13 1 9 10 17 8 7 1 9 5 2 16 7 9 12 13 5 1 4 6 6 15 2 8 10 4 5 4 1 15 17 3 9 7 6 1 14 8 14 7 2 2 13 1 5 19 11 6 1...
result:
ok ac (98934 test cases)
Test #6:
score: 0
Accepted
time: 6159ms
memory: 62988kb
input:
5 2000000 20 797234517 492602938 798908045 502327723 792452167 502906629 798928689 489396948 788980587 490810854 799097890 494409757 802136723 493677251 798645177 497015697 788761604 495701224 794885101 501374539 806251682 495921503 794079841 483699742 797040968 499798682 804797434 501060369 8094369...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok ac (5 test cases)
Test #7:
score: 0
Accepted
time: 834ms
memory: 3500kb
input:
100000 49 3 184136 65720 77810 18746 185003 61402 190816 51862 81874 16192 199764 65637 84958 7413 196301 60803 75931 6532 76068 9903 74087 524 188023 67224 67425 5134 71213 3955 78196 9061 73745 132 84239 12547 69698 611 185262 60938 189186 65907 85093 5693 73581 15566 197267 65267 67120 5883 84736...
output:
3 2 3 3 2 3 2 3 2 2 2 3 2 2 2 2 2 2 3 3 2 2 3 2 2 2 2 2 3 2 2 3 2 2 3 1 3 2 1 2 3 3 2 3 3 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 1 1 2 1 1 1 1 1 2 1 1 1 1 3 3 3 2 2 1 1 1 1 3 3 3 3 3 3 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 1 2 2 1 1 1 1 2 1 2 2 1 1 2 1 1 ...
result:
ok ac (100000 test cases)
Extra Test:
score: 0
Extra Test Passed