Submission #1257486

#TimeUsernameProblemLanguageResultExecution timeMemory
1257486AnphatArranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define uni(a) sort(all(a)), (a).resize(unique(all(a)) - (a).begin());

typedef pair <int, int> ii;

const int N = 2e5 + 10;

int n, a[N], f[N];
multiset <int> st[N];
ll ans;

void upd(int x, int y) {
    for (; x < N; x += x & -x)
        f[x] += y;
}

int get(int x) {
    int s = 0;
    for (; x; x -= x & -x)
        s += f[x];
    return s;
}

int get(int l, int r) {
    return get(r) - get(l - 1);
}

ll count_swaps() {
    cin >> n;
    for (int i = 1; i <= 2 * n; i++) {
        cin >> a[i];
        st[a[i] + n].insert(i);
        upd(i, 1);
    }

    for (int i = 1; i <= 2 * n; i++) {
        if (!sz(st[n - a[i]]))
            continue;

        if (!st[a[i] + n].count(i))
            continue;

        auto it = st[n - a[i]].lower_bound(i);
        if (it != st[n - a[i]].end()) {
            if (i + 1 <= *it - 1) ans += get(i + 1, *it - 1);
            if (get(i, 2 * n) % 2 == 0 && a[i] > 0) ans++;
            st[n - a[i]].erase(it);
            upd(*it, -1);
        }
    }
    return ans;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccFDQJuJ.o: in function `main':
grader.cpp:(.text.startup+0x289): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status