QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201878#5150. Alternating AlgorithmSolitaryDream#WA 1ms10248kbC++172.9kb2023-10-05 17:18:122023-10-05 17:18:12

Judging History

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

  • [2023-10-05 17:18:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:10248kb
  • [2023-10-05 17:18:12]
  • 提交

answer

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

#define int long long

const int N=1e6+1e3+7;

int n,a[N];

int w[N],s[N],b[N];

int cnt;

struct T{
    int l,r,ls,rs;
    int mx,tag;
}t[N*2+1];

void update(int x)
{
    t[x].mx=max(t[t[x].ls].mx,t[t[x].rs].mx);
}

void add(int x,int v)
{
    t[x].mx+=v;
    t[x].tag+=v;
}

void pushdown(int x)
{
    if(t[x].tag)
    {
        add(t[x].ls,t[x].tag);
        add(t[x].rs,t[x].tag);
        t[x].tag=0;
    }
}

int build(int l,int r)
{
    int x=++cnt;
    t[x].l=l,t[x].r=r;
    if(l==r)
    {
        t[x].mx=-1e15;
        return x;
    }
    int mid=(l+r)>>1;
    t[x].ls=build(l,mid);
    t[x].rs=build(mid+1,r);
    update(x);
    return x;
}

void change(int x,int l,int r,int v)
{
    if(l>r)
        return;
    if(l<=t[x].l&&t[x].r<=r)
    {
        add(x,v);
        return;
    }
    int mid=(t[x].l+t[x].r)>>1;
    pushdown(x);
    if(l<=mid)
        change(t[x].ls,l,r,v);
    if(r>mid)
        change(t[x].rs,l,r,v);
    update(x);
}

void setv(int x,int p,int v)
{
    if(t[x].l==t[x].r)
    {
        t[x].mx=v;
        return;
    }
    int mid=(t[x].l+t[x].r)>>1;
    pushdown(x);
    if(p<=mid)
        setv(t[x].ls,p,v);
    else
        setv(t[x].rs,p,v);
    update(x);
}

struct BIT{
    int c[N];

    void add(int x,int v)
    {
        while(x<=n)
        {
            c[x]+=v;
            x+=x&-x;
        }
    }

    int qry(int x)
    {
        int ret=0;
        while(x)
        {
            ret+=c[x];
            x-=x&-x;
        }
        return ret;
    }
}bit;

int vis[N];

signed main()
{
    scanf("%lld",&n);
    n++;
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    vector<int> id;
    for(int i=1;i<=n;i++)
        id.push_back(i);
    sort(id.begin(),id.end(),[&](const int &x,const int &y) {
        return a[x]>a[y]||(a[x]==a[y]&&x>y);
    });
    int ans=0;
    build(1,n);
    int suf=n+1;
    for(auto p:id)
    {
        int R=bit.qry(n)-bit.qry(p);
        bit.add(p,1);
        // cerr<<p<<" --- "<<endl;
        // b[p]=1;
        // int t=0;
        // for(int i=n;i>=1;i--)
        //     t+=(b[i]==1);
        // for(int i=1;i<=n;i++)
        // {
        //     s[i]=s[i-1]+(b[i]==1);
        //     w[i]=(n-(t-s[i])-i);
        //     if(w[i]!=0)
        //         w[i]+=(i&1?0:1);
        //     if(w[i]==0)
        //         continue;
        //     if(b[i]==0)
        //         continue;
        //     ans=max(ans,w[i]+s[i-1]);
        // }
        //n-R-p
        w[p]=n-R-p;
        if(w[p])
            w[p]+=(p&1?0:1);
        vis[p]=1;
        while(vis[suf-1])
            suf--;
        //suf ... n -INF
        setv(1,p,w[p]);
        change(1,suf,n,-1e9);
        change(1,p+1,n,1);
        change(1,1,p-1,-1);
        ans=max(ans,t[1].mx);
    }
    printf("%lld\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9932kb

input:

3
8 13 4 10

output:

3

result:

ok single line: '3'

Test #2:

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

input:

5
13 12 14 10 14 12

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 1ms
memory: 10032kb

input:

2
2 2 1

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 1ms
memory: 9944kb

input:

1
300172042 474444146

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 1ms
memory: 10248kb

input:

1
636357447 557539481

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 1ms
memory: 10008kb

input:

2
139715426 368724097 417561009

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 1ms
memory: 9928kb

input:

2
77784868 542697475 509604021

output:

2

result:

ok single line: '2'

Test #8:

score: 0
Accepted
time: 1ms
memory: 10192kb

input:

2
698395658 71848686 699775597

output:

1

result:

ok single line: '1'

Test #9:

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

input:

2
487635147 571273621 442673389

output:

3

result:

ok single line: '3'

Test #10:

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

input:

2
502022170 254766224 258867503

output:

2

result:

ok single line: '2'

Test #11:

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

input:

2
783651505 271735448 154090385

output:

2

result:

wrong answer 1st lines differ - expected: '3', found: '2'