QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#318872#7616. Jump Grapharnold518WA 1ms12056kbC++172.0kb2024-02-01 03:00:422024-02-01 03:00:43

Judging History

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

  • [2024-02-01 03:00:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:12056kb
  • [2024-02-01 03:00:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 3e5;

int N, A[MAXN+10];

struct SEG
{
    pii tree[MAXN*4+10];
    void init(int node, int tl, int tr)
    {
        if(tl==tr)
        {
            tree[node]=pii(A[tl], tl);
            return;
        }
        int mid=tl+tr>>1;
        init(node*2, tl, mid);
        init(node*2+1, mid+1, tr);
        tree[node]=max(tree[node*2], tree[node*2+1]);
    }
    pii query(int node, int tl, int tr, int l, int r)
    {
        if(l<=tl && tr<=r) return tree[node];
        if(r<tl || tr<l) return pii(0, 0);
        int mid=tl+tr>>1;
        return max(query(node*2, tl, mid, l, r), query(node*2+1, mid+1, tr, l, r));
    }
}seg;

ll ans[MAXN+10], dp1[MAXN+10], dp2[MAXN+10];
int L[MAXN+10], R[MAXN+10], sz[MAXN+10], root;
pii P[MAXN+10];

int dfs(int l, int r)
{
    if(l>r) return -1;
    int t=seg.query(1, 1, N, l, r).second;
    L[t]=dfs(l, t-1);
    R[t]=dfs(t+1, r);
    sz[t]=r-l+1;
    P[t]={l, r};
    return t;
}

void dfs2(int now)
{
    ll lv=0, rv=0, ls=0, rs=0;
    if(L[now]!=-1)
    {
        dfs2(L[now]);
        dp1[now]+=sz[L[now]]+dp1[L[now]];
        dp2[now]+=dp2[L[now]];
        lv=sz[L[now]]+dp1[L[now]];
        ls=sz[L[now]];
    }
    if(R[now]!=-1)
    {
        dfs2(R[now]); 
        dp1[now]+=dp1[R[now]];
        dp2[now]+=sz[R[now]]+dp2[R[now]];
        rv=sz[R[now]]+dp2[R[now]];
        rs=sz[R[now]];
    }
    ans[now]+=lv+rv;
    ans[now+1]-=lv+rv;
    auto [l, r] = P[now];
    ans[l]+=rv+rs+1;
    ans[now]-=rv+rs+1;
    ans[now+1]+=lv+ls+1;
    ans[r+1]-=lv+ls+1;
}

int main()
{
    scanf("%d", &N);
    for(int i=1; i<=N; i++) scanf("%d", &A[i]);

    seg.init(1, 1, N);
    root=dfs(1, N);
    dfs2(root);
    for(int i=1; i<=N; i++) ans[i]+=ans[i-1];
    for(int i=1; i<=N; i++) printf("%lld ", ans[i]);
    printf("\n");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 10004kb

input:

6
1 6 3 2 5 4

output:

11 7 7 7 6 8 

result:

ok single line: '11 7 7 7 6 8 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 12056kb

input:

2
1 2

output:

1 1 

result:

ok single line: '1 1 '

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 10092kb

input:

36
9 29 1 3 14 31 24 21 10 18 22 16 8 7 15 12 17 19 25 28 27 34 11 6 32 4 20 13 2 35 23 26 33 36 30 5

output:

101 98 99 99 100 87 81 79 79 79 73 72 71 71 70 72 72 77 83 94 107 100 120 120 116 118 116 116 116 113 142 142 143 143 175 175 

result:

wrong answer 1st lines differ - expected: '92 89 90 90 91 78 73 71 71 71 ...110 107 136 136 137 136 168 168', found: '101 98 99 99 100 87 81 79 79 7...16 113 142 142 143 143 175 175 '