QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#575165 | #9313. Make Max | Retr00 | WA | 0ms | 3592kb | C++20 | 1.4kb | 2024-09-19 11:00:13 | 2024-09-19 11:00:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 200001, INF = 0x3f3f3f3f;
ll ans, k;
set<ll> rt;
struct node
{
ll idx, val, fa, son[2];
void init(ll _idx, ll _val, ll _fa, ll s1)
{
idx = _idx, val = _val, fa = _fa, son[0] = 0, son[1] = s1;
}
} tree[N];
ll build(ll n)
{
for (int i = 1; i <= n; i++)
{
k = i - 1;
while (tree[k].val < tree[i].val)
k = tree[k].fa;
if (tree[k].val == tree[i].val)
{
rt.insert(tree[0].son[1]);
tree[0].init(0, INF, 0, i);
continue;
}
tree[i].son[0] = tree[k].son[1];
tree[k].son[1] = i;
tree[i].fa = k;
tree[tree[i].son[0]].fa = i;
}
return tree[0].son[1];
}
void dfs(ll x, ll d)
{
if (!x)
return;
ans += d;
dfs(tree[x].son[0], d + 1);
dfs(tree[x].son[1], d + 1);
return;
}
int main()
{
int T;
cin >> T;
while (T--)
{
ll n, h;
cin >> n;
ans = 0;
rt.clear();
tree[0].init(0, INF, 0, 0);
for (int i = 1; i <= n; i++)
{
cin >> h;
tree[i].init(i, h, 0, 0);
}
rt.insert(build(n));
for (auto p : rt)
dfs(p, 0);
cout << ans << '\n';
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3592kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 1 3
result:
wrong answer 3rd numbers differ - expected: '3', found: '1'