QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#610306#6434. Paimon Sortingucup-team4352#WA 0ms3716kbC++231.1kb2024-10-04 15:33:442024-10-04 15:33:45

Judging History

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

  • [2024-10-04 15:33:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3716kb
  • [2024-10-04 15:33:44]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define lowbit(x) (x&-x)
#define log(x) (31^__builtin_clz(x))
using namespace std;
const int maxn=1e5+5;
int a[maxn],vis[maxn];
int b[maxn];
ll ans[maxn];
int bit[maxn];
int n;
int qry(int x){
	int s=0;
	while(x){
		s+=bit[x];
		x-=lowbit(x);
	}
	return s;
}
void add(int x){
	while(x<=n){
		bit[x]++;
		x+=lowbit(x);
	}
}
void solve(){
	cin>>n;
	int tot=0;
	for(int i=1;i<=n;i++)cin>>a[i],vis[i]=0,bit[i]=0,ans[i]=0;
	for(int i=1;i<=n;i++){
		b[i]=max(a[i],b[i-1]);
	}
	for(int i=2;i<=n;i++){
		if(a[1]<a[i])swap(a[1],a[i]),ans[i]++;
		if(vis[a[i]]==0)vis[a[i]]=1,add(a[i]),tot++;
		int tmp=tot-qry(a[i]);
		int l=i,r=n+1;
		while(l<r){
			int mid=l+r-1>>1;
			if(!vis[b[mid]])r=mid;
			else l=mid+1;
		}
		ans[l]++;
		ans[i]+=tmp;
	}
	for(int i=1;i<=n;i++){
		cout<<(ans[i]+=ans[i-1])<<" ";
	}
	cout<<"\n";
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}
/*
3
 5
 2 3 2 1 5
 3
 1 2 3
 1
 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3716kb

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 1st lines differ - expected: '0 2 3 5 7', found: '0 2 3 5 7 '