QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#718506 | #6434. Paimon Sorting | nan_ling | WA | 0ms | 3648kb | C++17 | 1.3kb | 2024-11-06 20:42:14 | 2024-11-06 20:42:17 |
Judging History
answer
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define fixed(s) fixed<<setprecision(12)<<s
//#define int long long
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
typedef pair<ll, PII> PLII;
const int N = 100010;
int n;
int a[N];
int tr[N];
bool st[N];
int lowbit(int x)
{
return x & -x;
}
void add(int x, int c)
{
for(int i = x; i <= n; i += lowbit(i))
tr[i] += c;
}
int sum(int x)
{
int res = 0;
for(int i = x; i; i -= lowbit(i))
res += tr[i];
return res;
}
void solve()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
st[i] = 0, tr[i] = 0;
}
if(n == 1)
{
cout << 0 << endl;
return;
}
ll ans = 0;
int maxn = a[1];
cout << ans << ' ';
for(int i = 2; i <= n; i ++)
{
if(a[i] > maxn)
{
maxn = a[i];
ans += 2;
cout << ans << ' ';
if(!st[a[i]])
{
st[a[i]] = 1;
add(a[i], 1);
}
continue;
}
int t = sum(n) - sum(a[i]);
ans += t;
cout << ans;
if(i < n)cout << ' ';
if(!st[a[i]])
{
st[a[i]] = 1;
add(a[i], 1);
}
}
cout << endl;
}
int main()
{
IOS
int _;
cin >> _;
while(_ --)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3648kb
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 '