QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#575157#9313. Make MaxRetr00WA 0ms3664kbC++201.4kb2024-09-19 10:58:452024-09-19 10:58:50

Judging History

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

  • [2024-09-19 10:58:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3664kb
  • [2024-09-19 10:58:45]
  • 提交

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;
        ans = 0;
        cin >> n;
        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: 3664kb

input:

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

output:

1
0
1
10

result:

wrong answer 3rd numbers differ - expected: '3', found: '1'