QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567288#9313. Make MaxKelvin_LWA 55ms12376kbC++141002b2024-09-16 10:52:202024-09-16 10:52:21

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 10:52:21]
  • 评测
  • 测评结果:WA
  • 用时:55ms
  • 内存:12376kb
  • [2024-09-16 10:52:20]
  • 提交

answer

#include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;
const int N = 4e5 + 7;
int L[N], R[N];
bitset<N> vis;
struct Node { int x, c; } a[N], v[N];
int main() {
	int T, n;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		vis.reset();
		int m = 0;
		for (int i = 1, x; i <= n; ++i) {
			scanf("%d", &x);
			if (x == v[m].x) ++v[m].c;
			else a[++m] = {x, m}, v[m] = {x, 1}, vis[m] = 1;
			L[i] = i - 1, R[i] = i + 1;
		}
		sort(a+1, a+m+1, [](Node &x, Node &y) { 
			return x.x<y.x || (x.x==y.x && x.c<y.c); 
		});
		int ct = 0;
		for (int i = 1; i < m; ++i) {
			int id = a[i].c, l = L[id], r = R[id];
			if (!vis[id]) continue;
			L[r] = l, R[l] = r, vis[id] = 0;
			if (!l && r>m) break;
			if (l && v[l].x<v[r].x) 
				v[l].c += v[id].c;
			else if (v[l].x==v[r].x) {
				v[l].c += v[id].c + v[r].c, vis[r] = 0;
				r = R[r], L[r] = l, R[l] = r; 
			} else v[r].c += v[id].c;
			ct += v[id].c;
		}
		printf("%d\n", ct);
	}
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Wrong Answer
time: 55ms
memory: 12376kb

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:

3992210
3845256

result:

wrong answer 1st numbers differ - expected: '4084978', found: '3992210'