QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370101#6540. Beautiful SequenceGraphcityWA 1ms7900kbC++201.9kb2024-03-28 21:54:582024-03-28 21:54:58

Judging History

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

  • [2024-03-28 21:54:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7900kb
  • [2024-03-28 21:54:58]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=3e5;

inline int read()
{
    char ch=getchar();
    int f=1,x=0;
    while(ch>'9' || ch<'0')
    {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}

int n,m,a[Maxn+5],cnt[Maxn+5],id[Maxn+5];
int t[Maxn*4+5],sum[Maxn*4+5];
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)

inline void push_up(int p)
{
    sum[p]=sum[ls(p)]+sum[rs(p)];
    t[p]=min(t[ls(p)],sum[ls(p)]+t[rs(p)]);
}
inline void Build(int l,int r,int p)
{
    if(l==r) {t[p]=sum[p]=cnt[l]; return;}
    int mid=(l+r)>>1; Build(l,mid,ls(p)),Build(mid+1,r,rs(p)),push_up(p);
}
inline void Modify(int l,int r,int p,int pos,int k)
{
    if(pos>r) return;
    if(l==r) {sum[p]+=k,t[p]=min(sum[p],0); return;}
    int mid=(l+r)>>1;
    if(pos<=mid) Modify(l,mid,ls(p),pos,k);
    else Modify(mid+1,r,rs(p),pos,k);
    push_up(p);
}
inline void Clear() {For(i,1,n) cnt[i]=0; m=0;}
inline void Solve()
{
    vector<int> vx; n=read(); For(i,1,n) vx.push_back(a[i]=read());
    sort(vx.begin(),vx.end()),vx.erase(unique(vx.begin(),vx.end()),vx.end()),m=vx.size();
    For(i,1,n) a[i]=lower_bound(vx.begin(),vx.end(),a[i])-vx.begin()+1,cnt[a[i]]++;
    if(m==1) {printf("%d\n",n); Clear(); return;}
    Build(1,m-1,1),iota(id+1,id+m+1,1);
    sort(id+1,id+m+1,[&](int a,int b){return cnt[a]<cnt[b];});
    int ans=0; For(_,1,m)
    {
        int i=id[_],flg=0; while(cnt[i]--)
        {
            Modify(1,m-1,1,i,-1); if(!flg) Modify(1,m-1,1,i,-1);
            if(t[1]<0) {Modify(1,m-1,1,i,1); if(!flg) Modify(1,m-1,1,i,1);}
            else ans++,flg=1;
        }
    } printf("%d\n",ans); Clear();
}

int main()
{
    // freopen("1.in","r",stdin);

    int T=read();
    while(T--) Solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
6
1 1 2 3 3 4
5
1 2 2 3 3

output:

4
4

result:

ok 2 number(s): "4 4"

Test #2:

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

input:

2
5
1 2 2 3 3
20
1 1 1 1 1 1 4 5 8 8 8 8 9 9 9 9 10 10 10 10

output:

4
15

result:

wrong answer 2nd numbers differ - expected: '17', found: '15'