QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#575165#9313. Make MaxRetr00WA 0ms3592kbC++201.4kb2024-09-19 11:00:132024-09-19 11:00:14

Judging History

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

  • [2024-09-19 11:00:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-09-19 11:00:13]
  • 提交

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'