Submission #1279162

#TimeUsernameProblemLanguageResultExecution timeMemory
1279162lazylettuceArranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
// _                 _      _   _                  
//| | __ _ _____   _| | ___| |_| |_ _   _  ___ ___ 
//| |/ _` |_  / | | | |/ _ \ __| __| | | |/ __/ _ \lazylettuce
//| | (_| |/ /| |_| | |  __/ |_| |_| |_| | (_|  __/
//|_|\__,_/___|\__, |_|\___|\__|\__|\__,_|\___\___|
//             |___/                               
#include<bits/stdc++.h>

using namespace std;
using ll =long long ;
int MOD1=998244353;
int MOD2=1e9+7;

struct Fenwick {
    int n;
    vector<ll> bit;
    Fenwick(int n_ = 0) { init(n_); }
    void init(int n_) { n = n_; bit.assign(n+1, 0); }
    void update(int idx, ll delta = 1) {
        if (idx <= 0) return;
        for (; idx <= n; idx += idx & -idx) bit[idx] += delta;
    }
    ll query(int idx) {
        if (idx <= 0) return 0;
        ll res = 0;
        for (; idx > 0; idx -= idx & -idx) res += bit[idx];
        return res;
    }
    ll total() { return query(n); }
    ll inv_count(const vector<int>& v) {
        fill(bit.begin(), bit.end(), 0);
        ll inv = 0;
        for (int x : v) {
            if (x < 1 || x > n) {
                // skip bad indices (defensive)
                continue;
            }
            inv += (total() - query(x));
            update(x, 1);
        }
        return inv;
    }
};


long long count_swaps(vector<int>S){
    int m=S.size();
    vector<int>temp;
    vector<int>first;
    vector<int>left;

    map<int,vector<int>>right;
    for(int i=0;i<S.size();i++){
        if(S[i]<0){
            left.push_back(i+1);
        }
        else{
            right[S[i]].push_back(i+1);
        }
    }

    for(auto &it:right){
        reverse(it.second.begin(),it.second.end());
    }
    for(auto it:left){
        //  int magsafe = abs(S[it - 1]);
        int idx=right[-S[it-1]].back();
        right[-S[it-1]].pop_back();
        temp.push_back(it);
        temp.push_back(idx);
    }


    Fenwick f(m);
    ll ans=f.inv_count(temp);

    return ans;
}
int32_t  main(){
ios::sync_with_stdio(false);
int ji;
cin>>ji;
vector<int>v1(ji);
for(int i=0;i<ji;i++){
    cin>>v1[i];
}
cout<<count_swaps(v1)<<endl;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccvzmLyl.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccr6aGVE.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status