QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624431 | #6434. Paimon Sorting | GepiWang | WA | 0ms | 3824kb | C++23 | 1.4kb | 2024-10-09 15:50:10 | 2024-10-09 15:50:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define PII pair<int, int>
const int N = 1e5 + 5;
const int M = 1e5 + 5;
const int INF = 1e18 + 10;
int n;
int tr[N];
int lowbit(int x) { return x & -x; }
void add(int x, int d)
{
while (x <= n)
{
tr[x] += d;
x += lowbit(x);
}
}
int ask(int x)
{
int res = 0;
while (x)
{
res += tr[x];
x -= lowbit(x);
}
return res;
}
void solve()
{
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
tr[i] = 0;
}
int mx = a[1];
cout << 0 << " ";
int ans = 0;
vector<bool> st(n + 1);
st[a[1]] = true;
add(a[1], 1);
for (int i = 2; i <= n; i++)
{
if (a[i] > mx)
{
ans += 2;
}
else
{
int res = ask(n) - ask(a[i]);
// cout << "i= " << i << " " << a[i] << " " << ask(n) << " " << ask(a[i]) << endl;
ans += res;
}
mx = max(mx, a[i]);
if (!st[a[i]])
{
st[a[i]] = true;
add(a[i], 1);
}
cout << ans << " ";
}
cout << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
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: 0ms
memory: 3824kb
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 '