QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#774121#9792. Ogre Sortucup-team2112#WA 0ms3872kbC++202.0kb2024-11-23 11:54:322024-11-23 11:54:32

Judging History

This is the latest submission verdict.

  • [2024-11-23 11:54:32]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3872kb
  • [2024-11-23 11:54:32]
  • Submitted

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];
        ord[i] = i;
    }
    std::sort(ord.begin() + 1, ord.end(), [&](int x, int y) {
        return a[x] > a[y];
    });
    int mn = n + 1;
    std::vector<std::pair<int, int> > go;
    for (int o = 1; o <= n; o += 1) {
        int i = ord[o];
        if (mn < i) {
            go.emplace_back(mn, i);
        }
        mn = std::min(mn, i);
    }
    std::sort(go.begin(), go.end(), [&](auto x, auto y) {
        if (x.first != y.first) return x.first > y.first;
        return a[x.second] > a[y.second];
    });
    Fenwick_Tree tree(n + 5);
    for (int i = 1; i <= n; i += 1){
        tree.add(i, 1);
    }
    i64 cost = 0;
    std::vector<std::pair<int, int> > res;
    for (auto [x, y] : go) {
        int p = tree.query(y);
        res.emplace_back(p, x);
        tree.add(y, -1);
        tree.add(x + 1, 1);
        cost += x;
    }
    std::cout << cost << " " << res.size() << "\n";
    for (auto [x, y] : res) {
        std::cout << x << " " << y << "\n";
    }
    return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

4
1 2 4 3

output:

3 1
4 3

result:

ok Participant's output is correct

Test #2:

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

input:

5
2 4 1 3 5

output:

3 2
4 2
4 1

result:

ok Participant's output is correct

Test #3:

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

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #4:

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

input:

4
1 2 4 3

output:

3 1
4 3

result:

ok Participant's output is correct

Test #5:

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

input:

5
2 4 1 3 5

output:

3 2
4 2
4 1

result:

ok Participant's output is correct

Test #6:

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

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #7:

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

input:

1
1

output:

0 0

result:

ok Participant's output is correct

Test #8:

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

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

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

input:

5
1 3 4 2 5

output:

2 1
4 2

result:

ok Participant's output is correct

Test #11:

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

input:

5
1 4 5 2 3

output:

4 2
5 2
5 2

result:

wrong answer Integer parameter [name=participant answer] equals to 4, violates the range [0, 3]