QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#222242 | #7617. Spectacle | ucup-team1191# | WA | 1ms | 3504kb | C++20 | 1.5kb | 2023-10-21 16:23:57 | 2023-10-21 16:23:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)
const int M = 2e5 + 239;
int par[M], sz[M], sm;
int find_set(int p) {
if (par[p] == p) {
return p;
}
return par[p] = find_set(par[p]);
}
void merge(int i, int j) {
i = find_set(i);
j = find_set(j);
if (i == j) {
return;
}
if (sz[i] > sz[j]) {
swap(i, j);
}
sm -= sz[i] / 2;
sm -= sz[j] / 2;
par[i] = j;
sz[j] += sz[i];
sm += sz[j] / 2;
}
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
vector<pair<int, int>> v;
for (int i = 0; i + 1 < n; i++) {
v.emplace_back(a[i + 1] - a[i], i);
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
}
sm = 0;
vector<int> ans((n / 2), -1);
for (auto [val, i] : v) {
int last_sm = sm;
merge(i, i + 1);
for (int x = last_sm + 1; x <= sm; x++) {
ans[x - 1] = val;
}
}
for (int i : ans) {
cout << i << " ";
}
cout << "\n";
}
int main() {
#ifdef ONPC
freopen("input", "r", stdin);
#endif
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3504kb
input:
6 100 13 20 14 10 105
output:
1 5 6
result:
ok single line: '1 5 6 '
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3484kb
input:
2 1 1000000000000000000
output:
2147483646
result:
wrong answer 1st lines differ - expected: '999999999999999999', found: '2147483646 '