QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#626574 | #6434. Paimon Sorting | Crying | WA | 2ms | 13960kb | C++14 | 1.3kb | 2024-10-10 10:20:27 | 2024-10-10 10:20:28 |
Judging History
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 '