QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#603218#6434. Paimon Sortingucup-team3519#WA 2ms7752kbC++201.1kb2024-10-01 15:19:002024-10-01 15:19:01

Judging History

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

  • [2024-10-01 15:19:01]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7752kb
  • [2024-10-01 15:19:00]
  • 提交

answer

#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200005;
const ll mod=998244353;
struct BIT{
    vector<int> old;
    ll fenT[4*N];
    void add(int x,ll d) {assert(x>0);while(x<4*N) {fenT[x]+=d,old.push_back(x);x+=x&(-x);}}
    void add(int l,int r,ll d) {add(l,d);add(r+1,-d);}
    ll query(int x) {ll ans=0;while(x>=1) {ans+=fenT[x];x-=x&-x;}return ans;}
    ll query(int l,int r) {if(r<l)return 0;return query(r)-query(l-1);}
    void clear() {for(auto p: old) fenT[p]=0;old.clear();}
}bit;
void solve(){
	ll n;
	cin>>n;
	vector<int>a(n+1);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	ll rev=0,mx=0,mxlen=0;
	ll cnt=0;	
	bit.clear();
	vector<int>c(n+1);
	for(int i=1;i<=n;i++){
		if(c[a[i]]==0)
		bit.add(a[i],1);
		
		c[a[i]]++;
		rev+=bit.query(a[i]+1,n);
		if(a[i]==mx){
			cnt++;
		}
		else if(a[i]>mx){
			mx=a[i];
			mxlen++;
		}
		cout<<rev+2*mxlen-2+cnt<<' ';
//		cout<<rev<<' '<<mxlen<<' '<<cnt<<'\n';
	}
	cout<<'\n';
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin>>t;
	while(t--)
	solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 7752kb

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 '