QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#443482#6540. Beautiful SequenceFirminoWA 2ms4888kbC++141.3kb2024-06-15 15:42:012024-06-15 15:42:02

Judging History

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

  • [2024-06-15 15:42:02]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4888kb
  • [2024-06-15 15:42:01]
  • 提交

answer

#include <iostream>
#include <algorithm>
using namespace std;
int read(){
	int re=0,c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') re=(re<<3)+(re<<1)+(c^48),c=getchar();
	return re;
}
const int maxn=3e5+5;
struct P{
	int v,id;
}ps[maxn];
int n,lg[maxn],a[maxn],sz[maxn],pos[maxn],cd,sl[maxn],sum[maxn][2];
void init(){
	a[n+1]=cd=0;
}
void pre(){
	for (int i=2;i<=3e5;i++) lg[i]=lg[i>>1]+1;
}
bool cmp(P x,P y){return x.v<y.v;}
int lowb(int x){return x&(-x);}
void upd(int p,int v){
	while(p<=cd) sum[p][0]++,sum[p][1]+=v,p+=lowb(p);
}
int fd(int x){
	int re=0,p=0;
	for (int i=lg[cd];i>=0;i--){
		int np=p+(1<<i);
		if(np<=cd&&sum[np][1]<=x) re+=sum[np][0],x-=sum[np][1],p=np;
	}
	return re;
}
void solve(){
	n=read();
	init();
	for (int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	int st=1;
	for (int i=2;i<=n+1;i++){
		if(a[i]!=a[i-1]) sz[++cd]=i-st,st=i;
	}
	for (int i=1;i<=cd;i++)
		sl[i]=sl[i-1]+sz[i],ps[i]=(P){sz[i],i},sum[i][0]=sum[i][1]=0;
	sort(ps+1,ps+cd+1,cmp);
	for (int i=1;i<=cd;i++) pos[ps[i].id]=i;
	int ans=n-cd+1;
	for (int i=1;i<=cd;i++)
	{
		upd(pos[i],sz[i]);
		if(sl[i]<cd-i-1) continue;
		int tp=fd(cd-i-1);
		ans=max(ans,n-(cd-i-1)-(i-tp));
	}
	cout<<ans<<endl;
}
int main(){
	int t=read();pre();
	while(t--) solve();
	return 0;
}

詳細信息

Test #1:

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

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: 0ms
memory: 4788kb

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: 2ms
memory: 4888kb

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
10
10
12
14
10
9
10
10
8
9
9
9
11
11
10
9
9
12
10
9
10
9
10
10
11
10
10
11
9
8
10
10
9
10
10
13
10
12
11
10
9
10
9
10
11
10
10
8
11
9
10
9
10
9
10
9
11
11
11
9
10
10
9
9
8
10
11
11
10
10
9
9
10
9
10
9
10
9
9
10
8
10
8
11
9
11
11
12
8
9
10
8
12
11
10
11
9
10
11
9
9
8
10
8
10
10
9
10
8
9
10
11
10...

result:

wrong answer 3rd numbers differ - expected: '11', found: '10'