QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#567252#9313. Make MaxKelvin_LWA 54ms12572kbC++141001b2024-09-16 10:34:412024-09-16 10:34:41

Judging History

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

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

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, i}, 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>n) 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;
				r = R[r], L[r] = l, R[l] = r, vis[r] = 0; 
			} else v[r].c += v[id].c;
			ct += v[i].c;
		}
		printf("%d\n", ct);
	}
}



详细

Test #1:

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

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: 54ms
memory: 12572kb

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:

494337
474976

result:

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