Submission #736982

#TimeUsernameProblemLanguageResultExecution timeMemory
736982tvladm2009Arranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "shoes.h"
 
using namespace std;
 
typedef long long ll;
 
const int N_MAX = 100000;
 
int A[2 * N_MAX + 2];
std::deque <int> Minus[N_MAX + 2], Plus[N_MAX + 2];
int nxt[2 * N_MAX + 2];
bool used[N_MAX + 2];
 
int BIT[2 * N_MAX + 2];
void update(int pos, int val) {
    for (int i = pos; i <= 2 * N_MAX; i += i & -i) {
        BIT[i] += val;
    }
}
int query(int pos) {
    int answer = 0;
    for (int i = pos; i >= 1; i -= i & -i) {
        answer += BIT[i];
    }
    return answer;
}
 
int count_swaps(std::vector <int> S) {
    int N = (int) S.size() / 2;
    for (int i = 1; i <= 2 * N; i++) {
        A[i] = S[i - 1];
    }
    for (int i = 1; i <= 2 * N; i++) {
        if (A[i] < 0) {
            Minus[A[i] * -1].push_back(i);
        } else {
            Plus[A[i]].push_back(i);
        }
    }
    for (int i = 1; i <= 2 * N; i++) {
        if (A[i] < 0) {
            if (Plus[A[i] * -1].empty() == false) {
                nxt[i] = Plus[A[i] * -1].front();
            }
            Minus[A[i] * -1].pop_front();
        } else {
            if (Minus[A[i]].empty() == false) {
                nxt[i] = Minus[A[i]].front();
            }
            Plus[A[i]].pop_front();
        }
    }
 
    ll answer = 0;
    for (int i = 1; i <= 2 * N; i++) {
        if (used[i] == false) {
            int j = nxt[i];
            int between = query(j - 1) - query(i);
            int swaps = (j - i - 1) - between;
            if (A[i] > 0) {
                swaps++;
            }
            answer += swaps;
            used[i] = true;
            used[j] = true;
            update(i, +1);
            update(j, +1);
        }
    }
    return answer;
}

Compilation message (stderr)

shoes.cpp:29:5: error: ambiguating new declaration of 'int count_swaps(std::vector<int>)'
   29 | int count_swaps(std::vector <int> S) {
      |     ^~~~~~~~~~~
In file included from shoes.cpp:2:
shoes.h:7:11: note: old declaration 'long long int count_swaps(std::vector<int>)'
    7 | long long count_swaps(std::vector<int> S);
      |           ^~~~~~~~~~~