QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#518066#7617. SpectacleCarameowWA 0ms11876kbC++202.1kb2024-08-13 15:27:252024-08-13 15:27:26

Judging History

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

  • [2024-08-13 15:27:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11876kb
  • [2024-08-13 15:27:25]
  • 提交

answer

#include<bits/stdc++.h>
#define ii pair<int, int>
#define iii pair<int, ii>
using namespace std;

const int N = 2e5 + 10;

int n, ans;
int a[N], f[N], l[N], s[N];
int od[18][N], ev[18][N];
bool red[N];
priority_queue<iii, vector<iii>, greater<iii> > pq;

void init() {
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];
}

int getod(int f, int l) {
   f = f / 2 + 1;
   l = l / 2 + 1;
   int j = log2(l - f + 1);
   return max(od[j][f], od[j][l - (1 << j) + 1]);
}

int getev(int f, int l) {
   f /= 2;
   l /= 2;
   int j = log2(l - f + 1);
   return max(ev[j][f], ev[j][l - (1 << j) + 1]);
}

int main () {
	cin.tie(0) -> sync_with_stdio(0);
	if(fopen("Task.inp", "r")) {
		freopen("Task.inp", "r", stdin);
		freopen("Wa.out", "w", stdout);
	}

	init();
	int m1 = n / 2, m2 = n / 2 + n % 2 - 1;
	int lg = log2(n / 2);

	sort(a + 1, a + n + 1);
//	for(int i = 1; i <= n; ++i) cout << a[i] << " "; cout << "\n";

	for(int i = 1; i <= n; i += 2) od[0][i / 2 + 1] = a[i + 1] - a[i];
	for(int i = 2; i <= n; i += 2) ev[0][i / 2] = a[i + 1] - a[i];

   for(int j = 1; j <= lg; ++j) {
      for(int i = 1; i <= m1 - (1 << j - 1); ++i) {
         od[j][i] = max(od[j - 1][i], od[j - 1][i + (1 << j - 1)]);
      }
      for(int i = 1; i <= m2 - (1 << j - 1); ++i) {
         ev[j][i] = max(ev[j - 1][i], ev[j - 1][i + (1 << j - 1)]);
      }
	}

	for(int i = 0; i <= n; ++i) {
		f[i + 1] = i; l[i] = i + 1;
		if(i && n - i) pq.push({a[i + 1] - a[i], {i, i + 1}});
	}

	for(int i = 1; i <= n / 2; ++i) {
		while(!pq.empty()) {
			int mx, F, L;
			mx = pq.top().first;
         tie(F, L) = pq.top().second;
			pq.pop();

//			cout << mx << " " << F << " " << L << "\n";
			if(red[F] || red[L]) continue;

			ans = mx;
			red[F] = red[L] = 1;

			int nxtf = f[F], nxtl = l[L] - 1;
			if(!nxtf || nxtl == n) break;

			int val = nxtf % 2 ? getod(nxtf, nxtl) : getev(nxtf, nxtl);

			f[nxtl + 1] = nxtf;
			l[nxtf] = nxtl + 1;

         pq.push({val, {nxtf, nxtl + 1}});
         break;
		}

		cout << ans << "\n";
	}
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 11876kb

input:

6
100 13 20 14 10 105

output:

1
5
6

result:

wrong answer 1st lines differ - expected: '1 5 6', found: '1'