QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#718498 | #6434. Paimon Sorting | Chihiro | WA | 0ms | 3616kb | C++17 | 1.5kb | 2024-11-06 20:41:10 | 2024-11-06 20:41:11 |
Judging History
answer
#include <bits/stdc++.h>
#define fixed(s) fixed<<setprecision(12)<<s
using namespace std;
typedef long long ll;
typedef array<int, 3> Arr;
typedef pair<int, int> PII;
const int N = 2e5 + 7;
int n;
int tr[N], 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;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
if (n == 1){
cout << "0\n";
return;
}
vector<int> ans(n + 1);
ans[1] = 0;
add(a[1], 1), st[a[1]] = 1;
if (!st[a[2]]) add(a[2], 1), st[a[2]] = 1;
int cnt = 0;
for (int i = 1; i <= 2; i++){
for (int j = 1; j <= 2; j++){
if (a[i] < a[j]){
swap(a[i], a[j]);
cnt++;
}
}
}
ans[2] = cnt;
for (int i = 3; i <= n; i++){
// if (i == 5) cerr << sum(n) - sum(a[i]);
int t = sum(n) - sum(a[i]);
if (t == 0 && !st[a[i]]) ans[i] = ans[i - 1] + 2;
else ans[i] = ans[i - 1] + t;
if (!st[a[i]]) add(a[i], 1);
st[a[i]] = 1;
}
for (int i = 1; i <= n; i++){
cout << ans[i];
if (i != n) cout << ' ';
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.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: 3616kb
input:
3 5 2 3 2 1 5 3 1 2 3 1 1
output:
0 2 3 5 7 0 2 2 0
result:
wrong answer 2nd lines differ - expected: '0 2 4', found: '0 2 2'