QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#818643 | #9792. Ogre Sort | kkzyr | WA | 1ms | 7656kb | C++17 | 1.7kb | 2024-12-18 00:40:34 | 2024-12-18 00:40:35 |
Judging History
answer
#include <iostream>
using namespace std;
const int MAX_N = 3e5 + 5;
struct node{
int left, right;
int sum;
};
node merge(node x, node y){
return {x.left, y.right, x.sum + y.sum};
}
int n;
int nums[MAX_N];
int size_tree;
node tree[4 * MAX_N];
int place[MAX_N];
void set(int index){
index += size_tree - 1;
tree[index].sum = 1;
index /= 2;
while (index >= 1){
tree[index] = merge(tree[2 * index], tree[2 * index + 1]);
index /= 2;
}
}
int position;
void find_pos(int index, int tree_node){
int left_bound = tree[tree_node].left, right_bound = tree[tree_node].right;
if (right_bound < index){
return;
}
if (left_bound >= index and right_bound >= index){
position += tree[tree_node].sum;
return;
}
find_pos(index, 2 * tree_node);
find_pos(index, 2 * tree_node + 1);
}
int main(){
cin >> n;
for (int i = 1;i <= n;i++){
cin >> nums[i];
place[nums[i]] = i;
}
int pos = n;
int val = n;
while (pos >= 1){
while (pos >= 1 and nums[pos] != val){
pos--;
}
if (pos >= 1){
val--;
}
}
cout << val << '\n';
cout << val << '\n';
size_tree = 1;
while (size_tree < n){
size_tree *= 2;
}
for (int i = 1;i <= size_tree;i++){
tree[size_tree - 1 + i] = {i, i, 0};
}
for (int i = size_tree - 1;i >= 1;i--){
tree[i] = merge(tree[2 * i], tree[2 * i + 1]);
}
for (int i = val;i >= 1;i--){
position = 0;
find_pos(place[i], 1);
cout << position + place[i] << ' ' << 1 << '\n';
set(position + place[i]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5676kb
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: 1ms
memory: 5596kb
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: 0
Accepted
time: 1ms
memory: 5652kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #4:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
4 1 2 4 3
output:
3 3 4 1 3 1 3 1
result:
ok Participant's output is correct
Test #5:
score: 0
Accepted
time: 1ms
memory: 5720kb
input:
5 2 4 1 3 5
output:
3 3 4 1 2 1 4 1
result:
ok Participant's output is correct
Test #6:
score: 0
Accepted
time: 1ms
memory: 5648kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #7:
score: 0
Accepted
time: 1ms
memory: 5616kb
input:
1 1
output:
0 0
result:
ok Participant's output is correct
Test #8:
score: 0
Accepted
time: 1ms
memory: 5588kb
input:
5 5 3 4 1 2
output:
4 4 3 1 3 1 5 1 5 1
result:
ok Participant's output is correct
Test #9:
score: -100
Wrong Answer
time: 0ms
memory: 7656kb
input:
5 4 1 2 3 5
output:
3 3 4 1 4 1 3 1
result:
wrong answer participant's moves don't sort the array