QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#818773#9792. Ogre SortkkzyrWA 1ms7724kbC++171.8kb2024-12-18 08:43:172024-12-18 08:43:17

Judging History

This is the latest submission verdict.

  • [2024-12-18 08:43:17]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7724kb
  • [2024-12-18 08:43:17]
  • 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 << ' ' << 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] - val + i, 1);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #4:

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

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

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

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #7:

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

input:

1
1

output:

0 0

result:

ok Participant's output is correct

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 5640kb

input:

5
5 3 4 1 2

output:

4 4
3 1
3 1
5 1
4 1

result:

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