QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#818639#9792. Ogre SortkkzyrWA 1ms7584kbC++171.8kb2024-12-18 00:31:452024-12-18 00:31:45

Judging History

This is the latest submission verdict.

  • [2024-12-18 00:31:45]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7584kb
  • [2024-12-18 00:31:45]
  • Submitted

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 update(int index, int change){
    index += size_tree - 1;
    tree[index].sum += change;
    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';
        update(position + place[i], 1);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5636kb

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: 5700kb

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: 5588kb

input:

3
1 2 3

output:

0
0

result:

ok Participant's output is correct

Test #4:

score: 0
Accepted
time: 1ms
memory: 5548kb

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: 0ms
memory: 5644kb

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: 0ms
memory: 5696kb

input:

3
1 2 3

output:

0
0

result:

ok Participant's output is correct

Test #7:

score: 0
Accepted
time: 1ms
memory: 5624kb

input:

1
1

output:

0
0

result:

ok Participant's output is correct

Test #8:

score: 0
Accepted
time: 1ms
memory: 5700kb

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: 0
Accepted
time: 1ms
memory: 5636kb

input:

5
4 1 2 3 5

output:

3
3
4 1
4 1
4 1

result:

ok Participant's output is correct

Test #10:

score: 0
Accepted
time: 1ms
memory: 7584kb

input:

5
1 3 4 2 5

output:

2
2
4 1
2 1

result:

ok Participant's output is correct

Test #11:

score: 0
Accepted
time: 0ms
memory: 5700kb

input:

5
1 4 5 2 3

output:

3
3
5 1
5 1
3 1

result:

ok Participant's output is correct

Test #12:

score: 0
Accepted
time: 0ms
memory: 5648kb

input:

5
1 5 4 3 2

output:

4
4
3 1
4 1
5 1
4 1

result:

ok Participant's output is correct

Test #13:

score: -100
Wrong Answer
time: 1ms
memory: 5540kb

input:

5
3 2 1 5 4

output:

4
4
5 1
2 1
4 1
5 1

result:

wrong answer participant's moves don't sort the array