QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#652675#6434. Paimon Sortinglllei#WA 1ms3676kbC++141.3kb2024-10-18 18:59:412024-10-18 18:59:41

Judging History

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

  • [2024-10-18 18:59:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3676kb
  • [2024-10-18 18:59:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
struct TREE{
	int to[2],siz;
}tree[N*22];
int siz=1;
void push(int num)
{
	int now=1;
	tree[now].siz++;
	for(int i=20;i>=0;i--)
	{
		int to=0;
		if(num&(1<<i)) to=1;
		else to=0;
		if(!tree[now].to[to])
		{
			tree[now].to[to]=++siz;
			tree[siz]=tree[0];
		}
		now=tree[now].to[to];
		tree[now].siz++;
	}
	return;
}
int rnk(int num)
{
	int ct=0;
	int now=1;
	for(int i=20;i>=0;i--)
	{
		int to=0;
		if(num&(1<<i)) to=1;
		else to=0;
		if(to)
		{
			if(tree[now].to[0])
				ct+=tree[tree[now].to[0]].siz;
		}
		if(tree[now].to[to]){
			now=tree[now].to[to];
		}
		else return ct;
	}
	ct+=tree[now].siz;
	return ct;
}
int n,a[N],vis[N];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
		siz=1;
		tree[1]=tree[0];
		cin>>n;
		for(int i=1;i<=n;i++) vis[i]=0;
		for(int i=1;i<=n;i++) cin>>a[i];
		long long ans=0;
		cout<<ans<<' ';
		int mx=0;
		int ct=0;
		for(int i=2;i<=n;i++)
		{
			if(a[1]<a[i])
			{
				ans++;
				swap(a[1],a[i]);
			}
			mx=max(mx,a[i]);
			ans+=(i-2)-ct-rnk(a[i]);
			if(!vis[a[i]])
			{
			push(a[i]);
			vis[a[i]]=1;
			}
			else ct++;
			if(mx<a[1]) ans++;
			if(i!=n)
			cout<<ans<<' ';
			else cout<<ans;
		}
		cout<<'\n';
	}
	return 0;
}

详细

Test #1:

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

input:

3
5
2 3 2 1 5
3
1 2 3
1
1

output:

0 2 3 5 7
0 2 4
0 

result:

wrong answer 3rd lines differ - expected: '0', found: '0 '