QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#624294#7617. SpectacleLX1288#Compile Error//C++20928b2024-10-09 15:28:342024-10-09 15:28:35

Judging History

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

  • [2024-10-09 15:28:35]
  • 评测
  • [2024-10-09 15:28:34]
  • 提交

answer

#include"bits/stdc++.h"
using namespace std;
#define int long long
int const N = 2e6 + 3;
int n, r[N], fa[N], sz[N], ans[N];
struct node {
	int x, I, J;
}a[N];

bool cmp(node A, node B) {
	return A.x < B.x;
}

int find(int x) {
	if (x == fa[x]) return fa[x];
	else return fa[x] = find(fa[x]);
}

signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> r[i];
	sort(r + 1, r + n + 1);
	for (int i = 1; i < n; i++)
		a[i].x = r[i + 1] - r[i], a[i].I = i, a[i].J = i + 1;
	sort(a + 1, a + n, cmp);
	for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;
	int cnt = 0;
	for (int i = 1; i < n; i++) {
		int X = a[i].I, Y = a[i].J
		X = find(X), Y = find(Y);
		if (X == Y) continue;
		if (sz[X] % 2 == 1 && sz[Y] % 2 == 1) ans[++cnt] = a[i].x;
		fa[X] = Y;
		sz[Y] += sz[X];
	}
	for (int i = 1; i <= (n / 2); i++) cout << ans[i] << ' ';
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:31:17: error: expected ‘,’ or ‘;’ before ‘X’
   31 |                 X = find(X), Y = find(Y);
      |                 ^