QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#774173 | #9792. Ogre Sort | ucup-team2112# | WA | 0ms | 3852kb | C++20 | 1.6kb | 2024-11-23 12:14:45 | 2024-11-23 12:14:47 |
Judging History
answer
#include <bits/stdc++.h>
struct Fenwick_Tree{
std::vector<int> c;
int n;
Fenwick_Tree(int n) : n(n) {
c.resize(n + 1);
}
void add(int x, int y) {
for (int i = x; i <= n; i += i & -i) {
c[i] += y;
}
}
int query(int x) {
int res = 0;
for (int i = x; i > 0; i -= i & -i) {
res += c[i];
}
return res;
}
int kth(int k) {
int res = 0;
for (int i = 1 << std::__lg(n); i > 0; i >>= 1) {
if (res + i <= n && c[res + i] < k) {
k -= c[res + i];
res += i;
}
}
return res + 1;
}
};
using i64 = long long;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(n + 1);
std::vector<int> ord(n + 1);
for (int i = 1; i <= n; i += 1){
std::cin >> a[i];
}
Fenwick_Tree tree(n);
for (int i = n; i >= 0; i -= 1) {
if (i && i == a[i]) continue;
std::cout << i - 1 << " " << i - 1 << "\n";
std::vector<int> ord(i + 1);
for (int j = 1; j <= i; j += 1) {
ord[j] = j;
}
std::sort(ord.begin() + 1, ord.end(), [&](int x, int y) {
return a[x] > a[y];
});
for (int j = 2; j <= i; j += 1) {
std::cout << ord[j] + tree.query(n - ord[j] + 1) << " " << 1 << "\n";
tree.add(n - ord[j] + 1, 1);
}
break;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
input:
4 1 2 4 3
output:
3 3 4 1 3 1 3 1
result:
ok Participant's output is correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
5 2 4 1 3 5
output:
3 3 4 1 2 1 4 1
result:
ok Participant's output is correct
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3620kb
input:
3 1 2 3
output:
-1 -1
result:
wrong answer Integer parameter [name=participant answer] equals to -1, violates the range [0, 0]