QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#626807 | #6434. Paimon Sorting | Corzica | WA | 1ms | 5700kb | C++14 | 1.1kb | 2024-10-10 13:11:24 | 2024-10-10 13:11:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, a[500005], qwe;
vector<pair<int, int>> changes;
int t[500005], ans[500005];
inline int lowbit(int p) {
return p & -p;
}
inline void change(int p, int q, int flg = 1) {
if (flg) changes.push_back(make_pair(p, q));
while (p <= n) {
t[p] += q;
p += lowbit(p);
}
}
inline int query(int p) {
int cnt = 0;
while (p) {
cnt += t[p];
p -= lowbit(p);
}
return cnt;
}
inline void clear() {
for (pair<int, int> op : changes) {
change(op.first, -op.second, 0);
}
changes.clear();
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> qwe;
while (qwe--) {
clear();
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int lst = 0, num = -1, lsts = 0, aans = 0;
for (int i = 1; i <= n; i++) {
if (query(a[i] - 1) == query(n)) {
aans += i - 1 - lst;
lst = i, num++;
}
ans[i] = ans[i - 1] + query(n) - query(a[i]);
if (query(a[i]) == query(a[i] - 1)) change(a[i], 1);
cout << ans[i] + num + (lst - 1) - aans << ' ';
}
cout << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5700kb
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 '