Submission #560089

#TimeUsernameProblemLanguageResultExecution timeMemory
560089PoonYaPatArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

int n,ans,fen[200001],a[200001];
queue<int> pos[200001];
bool vis[200001];

int find(int x) {
    int sum=0;
    while (x) {
        sum+=fen[x];
        x-=(int)(x&-x);
    }
    return sum;
}

void update(int x, int y) {
    while (x<=2*n) {
        fen[x]+=y;
        x+=(x&-x);
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=1; i<=2*n; ++i) {
        cin>>a[i];
        if (a[i]<0) a[i]=n-a[i];
        pos[a[i]].push(i);
    }

    for (int i=1; i<=2*n; ++i) {
        if (vis[i]) continue;
        int k=a[i];

        if (k<=n) { //right shoes, have to move left shoes
            while (vis[pos[k+n].front()]) pos[k+n].pop();
            int p=pos[k+n].front();
            pos[k+n].pop();
            ans+=(p+find(p)-1);
            update(i,-1);
            update(p,-1);
            vis[i]=true;
            vis[p]=true;

        } else { //left shoes, have to move right shoes
            while (vis[pos[k-n].front()]) pos[k-n].pop();
            int p=pos[k-n].front();
            pos[k-n].pop();
            ans+=(p+find(p)-2);
            update(i,-1);
            update(p,-1);
            vis[i]=true;
            vis[p]=true;
        }
    }
    cout<<ans;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccUpGUAH.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cclzsofH.o:shoes.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccUpGUAH.o: in function `main':
grader.cpp:(.text.startup+0x29d): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status