답안 #434819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
434819 2021-06-21T21:00:25 Z magmag Arranging Shoes (IOI19_shoes) C++17
10 / 100
29 ms 7088 KB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int mxN = 1e5+3;
ll idx[mxN];

struct FenwickTree {
    ll tr[mxN];

    ll LSB(ll x) {
        return (x) & (-x);
    }

    void add(ll i) {
        for (; i < mxN; i += LSB(i))++tr[i];
    }

    ll rsq(ll i) {
        ll s = 0;
        for (; i > 0; i -= LSB(i))s += tr[i];
        return s;
    }

    ll rsq(ll i, ll j) {
        return rsq(j) - (i > 1 ? rsq(i-1) : 0);
    }
};

long long count_swaps(std::vector<int> s) {
    int n = s.size();

    for (int i = 1; i <= n; ++i) {
        idx[abs(s[i-1])] = i;
    }

    FenwickTree ft;

    ll ans = 0;

    for (int i = 1; i <= n; ++i) {
        int curr = s[i-1];
        if (idx[abs(curr)] == i)continue;
        int nidx = idx[abs(curr)];

        ll dist = nidx - i - 1 - ft.rsq(i, nidx);

        if (s[i-1] > 0)++dist;
        ans += dist;
        ft.add(nidx);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Incorrect 1 ms 972 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Incorrect 1 ms 972 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Runtime error 29 ms 7088 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Incorrect 1 ms 972 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Incorrect 1 ms 972 KB Output isn't correct
15 Halted 0 ms 0 KB -