QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576675#9313. Make MaxAil_ijyqWA 1ms7676kbC++141.6kb2024-09-19 21:31:312024-09-19 21:31:32

Judging History

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

  • [2024-09-19 21:31:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7676kb
  • [2024-09-19 21:31:31]
  • 提交

answer

#include<bits/stdc++.h>
#define PII pair<int,int>
#define int long long
using namespace std;

const int N=2e5+10;
const int INF=1e9+10;
int a[N];
int c[N];
int fa[N];
int Size[N];
int n;
int lowbit(int x)
{
    return x & -x;
}
void ad(int x,int d)
{
    for (int i = x;i <= n;i += lowbit (i)) c[i] += d;
}
int sum (int x)
{
    int ans = 0;
    for (int i = x;i;i -= lowbit (i)) ans += c[i];
    return ans;
}
int find(int x)
{
    if(fa[x]==x)
        return x;
    else return fa[x]=find(fa[x]);
}
void add(int x,int y)//左合并到右
{
    fa[x]=y;
    if(a[x]!=a[y]) Size[y]+=Size[x];
    return ;
}

int search(int l,int r,int x)
{
    int mid;
    while(l<r)
    {
        mid=l+r>>1;
        if(sum(mid)>=x) r=mid;
        else l=mid+1;
    }
    return l;
}

void solve()
{
    cin>>n;
    memset(c,0,sizeof c);
    priority_queue<PII,vector<PII>,greater<PII> >heap;
    for(int i=1;i<=n;i++) cin>>a[i];
    int res=0;
    int Max=0;
    a[0]=a[n+1]=INF;
    for(int i=1;i<=n;i++)
    {
        ad(i,1);
        Size[i]=1;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==a[i+1])
        {
            ad(i,-1);
            add(i,i+1);
        }
        else heap.push({a[i],i}),Max=max(a[i],Max);
    }

    while(heap.top().first!=Max)
    {
        int x=heap.top().second;
        heap.pop();
        int l=search(0,n+1,sum(x)-1),r=search(0,n+1,sum(x)+1);
        if(a[l]>a[r]) add(x,r);
        else add(x,l);
        ad(x,-1);
        res+=Size[x];
    }
    cout<<res<<endl;
}

signed main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7676kb

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'