QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#628486 | #6434. Paimon Sorting | Lehe | WA | 2ms | 15868kb | C++23 | 1.7kb | 2024-10-10 20:32:32 | 2024-10-10 20:32:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fir first
#define sec second
#define chmin(a,b) (a=min(a,b))
#define chmax(a,b) (a=max(a,b))
const int inf=0x3f3f3f3f3f3f3f3f;
int a[500010],n,b[500010],ans[500010],vis[500010],premx[500010],cnt[500010],pc[500010],d[500010];
int lowbit(int x){return x&(-x);}
struct BIT
{
int c[500010];
void init(int n){for(int i=1;i<=n;i++)c[i]=0;}
void update(int x,int v){while(x<=n)c[x]+=v,x+=lowbit(x);}
int query(int x){int ans=0;while(x)ans+=c[x],x-=lowbit(x);return ans;}
}t;
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
// a[n+1]=n+1;
// ++n;
for(int i=1;i<=n;i++)b[i]=vis[i]=0,premx[i]=max(premx[i-1],a[i]),cnt[i]=0,d[i]=a[i];
for(int i=1;i<=n;i++)if(a[i]>a[1])swap(a[i],a[1]),b[i]=1;
// int cnt=0;
t.init(n);
// for(int i=1;i<=n;i++)cout<<a[i]<<" ";
// cout<<endl;
// for(int i=1;i<=n;i++)cout<<b[i]<<" ";
// cout<<endl;
for(int i=1,bbb=0;i<=n;i++)
{
// cnt+=b[i];
// cout<<" "<<i<<" "<<t.query(n)<<" "<<t.query(a[i])<<endl;
cnt[d[i]]++;
if(i>1)
{
// cnt[a[i]]++;
ans[i]=ans[i-1]+b[i]+t.query(n)-t.query(a[i])+1;
if(premx[i]!=premx[i-1])bbb=0;
bbb+=(cnt[premx[i]]>1&&a[i]!=premx[i]);
pc[i]=max(cnt[premx[i]]-1,0LL)+bbb;//(cnt[premx[i]]>1&&a[i]!=premx[i]);
// cout<<"! "<<i<<" "<<ans[i]<<" "<<pc[i]<<endl;
// cout<<"!!!"<<i<<" "<<ans[i-1]<<" "<<b[i]<<" "<<ans[i]<<endl;
if(!vis[a[i]])vis[a[i]]=1,t.update(a[i],1);
}
}
for(int i=1;i<=n;i++)cout<<ans[i]-pc[i]<<" ";
cout<<endl;
}
signed main()
{
// freopen("sort.in","r",stdin);
// freopen("sort.out","w",stdout);
int t;
cin>>t;
while(t--)solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 15868kb
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 '