QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#573209 | #6434. Paimon Sorting | ji_114514 | WA | 1ms | 8032kb | C++20 | 1.1kb | 2024-09-18 17:44:58 | 2024-09-18 17:44:59 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) (x&(-x))
using namespace std;
const int N = 1e6 + 10;
int a[N], n, s[N];
ll f[N];
void add(int x, int t) {
while (x <= n) {
s[x] += t;
x += lowbit(x);
}
}
int query(int x) {
int res = 0;
while (x) {
res += s[x];
x -= lowbit(x);
}
return res;
}
void solve()
{
cin >> n;
vector<int>v(1, 1);
for (int i = 1; i <= n; i++) {
cin >> a[i], f[i] = 0;
}
ll res = 0, t = 0;
add(a[1], 1);
for (int i = 2; i <= n; i++) {
if (a[i] > a[v.back()]) {
res += 2;
f[i] = res;
add(a[i], 1);
v.push_back(i);
}
else {
res += query(n) - query(a[i]);
//cout << i << ' ' << query(n) << "#\n";
f[i] = res;
}
}
for (int i = 1; i <= n; i++)cout << f[i] << ' ';
cout << '\n';
}
int main()
{
srand(time(0));
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t; 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: 1ms
memory: 8032kb
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 '