QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#275986#7617. Spectacleddl_VS_pigeon#WA 1ms3544kbC++201.3kb2023-12-05 13:36:192023-12-05 13:36:20

Judging History

你现在查看的是最新测评结果

  • [2023-12-05 13:36:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3544kb
  • [2023-12-05 13:36:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

struct DSU {
	vector<int> fa, sz;
	DSU(int n) : fa(n + 1), sz(n + 1) {
		for (int i = 0; i <= n; i++) {
			fa[i] = i, sz[i] = 1;
		}
	}
	int getfa(int v) {
		return (fa[v] == v) ? v : (fa[v] = getfa(fa[v]));
	}
	void merge(int u, int v) {
		u = getfa(u), v = getfa(v);
		if (u != v) {
			fa[u] = v, sz[v] += sz[u];
		}
	}
	int getsz(int v) {
		return sz[getfa(v)];
	}
};

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	struct T {
		int id, len;
		bool operator<(const T &b) const {
			return len < b.len;
		}
	};
	vector<T> t(n - 1);
	for (int i = 0; i + 1 < n; i++) {
		t[i] = {i, a[i + 1] - a[i]};
	}
	sort(t.begin(), t.end());
	vector<int> ans(n / 2 + 1);
	int cnt = 0, x = 0;
	DSU dsu(n);
	for (int i = 0; i + 1 < n; i++) {
		int v = t[i].id;
		cnt -= dsu.getsz(v) >> 1;
		cnt -= dsu.getsz(v + 1) >> 1;
		dsu.merge(v, v + 1);
		cnt += dsu.getsz(v) >> 1;
		while (x < cnt) {
			ans[++x] = t[i].len;
		}
	}
	for (int i = 1; i <= n / 2; i++) {
		cout << ans[i] << ' ';
	}
	cout << '\n';
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3428kb

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: 1ms
memory: 3544kb

input:

2
1 1000000000000000000

output:

2147483646 

result:

wrong answer 1st lines differ - expected: '999999999999999999', found: '2147483646 '