QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#684770 | #6434. Paimon Sorting | catch-up-from-behind# | WA | 0ms | 3812kb | C++17 | 1.5kb | 2024-10-28 15:45:53 | 2024-10-28 15:45:54 |
Judging History
answer
#include <bits/stdc++.h>
#define F(i,x,y) for(int i=(x);i<=(y);i++)
#define DF(i,x,y) for(int i=(x);i>=(y);i--)
#define ms(x,y) memset(x,y,sizeof(x))
#define SZ(x) (int)x.size()-1
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int> pii;
template<typename T> void chkmax(T &x,T y){ x=max(x,y);}
template<typename T> void chkmin(T &x,T y){ x=min(x,y);}
template<typename T> void read(T &FF){
FF=0;int RR=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') RR=-1;
for(;isdigit(ch);ch=getchar()) FF=(FF<<1)+(FF<<3)+ch-48;
FF*=RR;
}
const int N=100010;
int n,a[N];
struct fenwick{
int tr[N];
#define lowbit(x) x&-x
void clr(){ F(i,1,n) tr[i]=0;}
void add(int x){ for(;x<=n;x+=lowbit(x)) tr[x]++;}
int ask(int x){ int res=0;for(;x;x-=lowbit(x)) res+=tr[x];return res;}
}fwk;
int cnt[N];
void work(){
read(n);
F(i,1,n) read(a[i]);
F(i,1,n) cnt[i]=0;
fwk.clr();
int mx=a[1];printf("0 ");
fwk.add(a[1]),cnt[a[1]]++;
LL ans=0;
int S=0;bool fl=0;
F(i,2,n){
if(mx>a[i]) ans+=fwk.ask(n)-fwk.ask(a[i]);
else if(mx<a[i]) ans+=2+fl*S,fl=0,mx=a[i];
else if(cnt[a[i]]==1) S=0,fl=1;
S++;
if(!cnt[a[i]]) fwk.add(a[i]);
cnt[a[i]]++;
printf("%lld ",ans);
}puts("");
}
int main(){
int T;read(T);
while(T--) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3812kb
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 '