QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#575317 | #6434. Paimon Sorting | Harry27182 | WA | 0ms | 3620kb | C++14 | 813b | 2024-09-19 12:11:27 | 2024-09-19 12:11:28 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,n,a[100005],tr[100005],vis[100005];
void change(int x,int v){for(int i=x;i<=n;i+=i&(-i))tr[i]+=v;}
int query(int x){int res=0;for(int i=x;i;i-=i&(-i))res+=tr[i];return res;}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>T;
while(T--)
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)vis[i]=tr[i]=0;
int mx=a[1],ans=0,num=1;
change(a[1],1);vis[a[1]]=1;cout<<0<<' ';
for(int i=2;i<=n;i++)
{
if(a[i]>mx)
{
ans+=query(n)-query(mx)+1;
mx=a[i];num++;
if(!vis[a[i]])change(a[i],1),vis[a[i]]=1;
}
else
{
ans+=query(n)-query(a[i]);
if(!vis[a[i]])change(a[i],1),vis[a[i]]=1;
}
cout<<ans+num-1<<' ';
}
cout<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3620kb
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 '