QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#465934 | #6434. Paimon Sorting | younger | WA | 0ms | 3556kb | C++20 | 1.6kb | 2024-07-07 13:54:27 | 2024-07-07 13:54:27 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include <iomanip>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
typedef long long LL;
typedef __int128 i128;
typedef unsigned long long ULL;
typedef double db;
#define int long long
const int N = 1e5 + 10;
int n , a[N] , ans , st[N];
int tr[N];
int lowbit(int x){
return x & -x;
}
int query(int x){
int res = 0;
for(int i = x ; i ; i -= lowbit(i)){
res += tr[i];
}
return res;
}
void add(int x , int d){
for(int i = x ; i <= n ; i += lowbit(i)){
tr[i] += d;
}
return;
}
void Asuka()
{
ans = 0;
cin >> n;
for(int i = 1 ; i <= n ; i ++){
cin >> a[i];
st[i] = false;
tr[i] = 0;
}
int maxn = a[1] , cnt = 0;
bool flag = false;
add(a[1] , 1);
st[a[1]] = true;
cout << 0 << ' ';
for(int i = 2 ; i <= n ; i ++){
if(!st[a[i]]){
st[a[i]] = true;
add(a[i] , 1);
}
if(a[1] == a[i]){
cnt ++;
}
if(a[i] > a[1]){
ans += cnt + 1;
cnt = 0;
swap(a[i] , a[1]);
}
// cout << query(a[1]) << ' ' << query(a[i]) << ' ' << a[1] << ' ' << a[i] << '\n';
ans += query(a[1]) - query(a[i]);
// cout << a[1] << ' ' << a[i] << ' ';
cout << ans << ' ';
}
cout << '\n';
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while(t --){
Asuka();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3556kb
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 '