QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#626807#6434. Paimon SortingCorzicaWA 1ms5700kbC++141.1kb2024-10-10 13:11:242024-10-10 13:11:27

Judging History

你现在查看的是最新测评结果

  • [2024-10-10 13:11:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5700kb
  • [2024-10-10 13:11:24]
  • 提交

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";
	}
}

详细

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 '