QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#567190 | #9313. Make Max | CuberW | WA | 1ms | 6012kb | C++14 | 2.3kb | 2024-09-16 09:51:05 | 2024-09-16 09:51:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct node
{
int value, id;
int size = 0;
bool operator<(const node &x)const
{
return value > x.value;
}
};
const int N = 2e5 + 10;
node a[N];
priority_queue<node> heap;
int main()
{
int t;
cin >> t;
while (t--)
{
int ans = 0;
int n, idx = 0;
scanf("%d", &n);
vector<int> arr(n + 1, 0);
bool flag = true;
for (int i = 1; i <= n; i++)
{
scanf("%d", &arr[i]);
}
++idx;
a[idx].value = arr[1], a[idx].size = 1;
for (int i = 2; i <= n + 1; i++)
{
if (arr[i] != arr[i - 1])
{
idx++;
a[idx].value = arr[i], a[idx].size = 1;
}
else
{
a[idx].size++;
}
}
idx--;
if (idx == 1)
{
puts("0");
continue;
}
for (int i = 1; i <= idx; i++)
{
a[i].id = i;
heap.push(a[i]);
// cout << a[i].value << " " << a[i].size << endl;
}
while (heap.size() > 1)
{
node mn = heap.top(); heap.pop();
int i = mn.id;
int L = i - 1, R = i + 1;
while (a[L].size == 0 && L >= 1)
{
L--;
}
while (a[R].size == 0 && R <= n)
{
R++;
}
if (L == 0 && R <= n)
{
a[R].size += a[i].size;
ans += a[i].size;
a[i].size = 0;
}
else if (R == n + 1 && L >= 1)
{
a[L].size += a[i].size;
ans += a[i].size;
a[i].size = 0;
}
else if (L >= 1 and R <= n)
{
int ttt;
if (a[L].value > a[R].value) ttt = R;
else if (a[L].value < a[R].value) ttt = L;
if (a[L].value == a[R].value)
{
ttt = R;
a[L].size = 0;
}
a[ttt].size += a[i].size;
ans += a[i].size;
a[i].size = 0;
}
}
cout << ans << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6012kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 10 3
result:
wrong answer 3rd numbers differ - expected: '3', found: '10'