QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#626574#6434. Paimon SortingCryingWA 2ms13960kbC++141.3kb2024-10-10 10:20:272024-10-10 10:20:28

Judging History

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

  • [2024-10-10 10:20:28]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:13960kb
  • [2024-10-10 10:20:27]
  • 提交

answer

#include<bits/stdc++.h>
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;
const int N = 5e5+10;
int T,n,a[N],buc[N],nxt[N]; ll ans[N];

struct BIT{
    int t[N];
    void clear(){fill(t+1,t+1+n,0);}
    void mdf(int x,int v){
        x = n-x+1;
        for(;x<=n;x+=lowbit(x))t[x] += v;
    }
    int qry(int x,int S=0){
        x = n-x+1;
        for(;x;x-=lowbit(x))S += t[x];
        return S;
    }
}bit,bit2;

void set_v(int x,int p){
    buc[x]++;
    if(buc[x] == 2)nxt[x] = p;
}

void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];

    bit.clear(); bit2.clear(); 
    fill(buc+1,buc+1+n,0); fill(nxt+1,nxt+1+n,0);
    ans[1] = 0; bit.mdf(a[1],1); set_v(a[1],1);
    int pre = a[1];
    for(int i=2;i<=n;i++){
        ans[i] = ans[i-1];
        if(a[i] > pre){
            if(nxt[pre]){
                ans[i] += bit2.qry(nxt[pre]);
            }
            ans[i] += 2;
            bit.mdf(a[i],1);
            pre = a[i];
        }else{
            ans[i] += bit.qry(a[i]+1);
            if(!buc[a[i]])bit.mdf(a[i],1);
            bit2.mdf(i,1);
        }
        set_v(a[i],i);
    }
    for(int i=1;i<=n;i++)cout<<ans[i]<<" "; cout<<"\n";
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>T;
    while(T--)solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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 '