QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370122#6540. Beautiful SequenceGraphcityWA 1ms5796kbC++201.8kb2024-03-28 22:05:192024-03-28 22:05:20

Judging History

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

  • [2024-03-28 22:05:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5796kb
  • [2024-03-28 22:05:19]
  • 提交

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[rs(p)],sum[rs(p)]+t[ls(p)]);
}
inline void Build(int l,int r,int p)
{
    if(l==r) {t[p]=sum[p]=1; 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),iota(id+1,id+m+1,1);
    sort(id+1,id+m+1,[&](int a,int b){return cnt[a]<cnt[b];});
    int ans=m; For(_,1,m)
    {
        int i=id[_]; Modify(1,m,1,i,-(cnt[i]+1));
        if(t[1]<1) Modify(1,m,1,i,cnt[i]+1);
        else ans--;
    } printf("%d\n",n-(ans-1)); 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: 5784kb

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: 0
Accepted
time: 1ms
memory: 5796kb

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
17

result:

ok 2 number(s): "4 17"

Test #3:

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

input:

300
14
1 1 1 2 2 2 3 3 3 4 5 5 6 6
14
1 1 1 2 2 3 3 4 4 5 5 6 7 7
14
1 1 2 2 3 4 4 4 5 5 5 6 6 6
14
1 1 2 2 3 3 3 4 5 5 5 6 6 6
14
1 1 1 1 1 1 2 2 2 2 2 3 3 3
14
1 1 1 1 1 1 1 1 1 1 1 1 1 1
14
1 2 2 3 4 5 5 6 6 6 7 8 8 8
14
1 2 2 2 2 2 3 4 5 6 7 8 9 10
14
1 2 2 3 4 4 4 5 6 6 6 6 6 7
14
1 1 2 2 2 3 3...

output:

10
9
11
11
12
14
10
9
11
11
9
10
10
9
11
11
11
9
9
12
10
9
10
10
11
10
11
11
11
11
10
8
10
10
10
10
11
13
10
12
11
11
9
10
9
11
11
10
9
8
11
9
11
9
10
9
10
10
11
11
12
9
10
10
10
10
9
10
11
10
10
10
9
10
11
10
10
10
10
9
9
10
8
11
9
11
10
11
11
12
9
9
9
9
12
11
10
11
10
10
10
10
9
9
10
9
9
10
10
11
...

result:

wrong answer 49th numbers differ - expected: '10', found: '9'