Submission #1263956

#TimeUsernameProblemLanguageResultExecution timeMemory
1263956BlockOGArranging Shoes (IOI19_shoes)C++20
45 / 100
60 ms12104 KiB
#include <bits/stdc++.h>

// mrrrow meeow :3
// go play vivid/stasis now! it's free on steam

#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;

int ____init = [] {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    return 0;
}();

int bit[200001];

void add(int i, int v) {
    for (i++; i <= 200000; i += i & -i) bit[i] += v;
}

int get(int i) {
    int res = 0;
    for (i++; i > 0; i -= i & -i) res += bit[i];
    return res;
}

long long count_swaps(vector<int> s) {
    long long n = s.size() / 2;

    set<int> poss, negs;
    fo(i, 0, 2 * n) {
        if (s[i] > 0) poss.insert(i);
        else negs.insert(i);
        add(i, 1);
    }
    add(0, -1);

    long long res = 0;
    fo(_, 0, n) {
        int first_neg = *negs.begin();
        negs.erase(first_neg);
        int first_pos = *poss.begin();
        poss.erase(first_pos);

        res += get(first_neg);
        add(first_neg, -1);
        res += get(first_pos);
        add(first_pos, -1);
    }

    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...