Submission #1155463

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define pb                  push_back

typedef long long         ll;


long long count_swaps(std::vector<int> s) {
	int n;
    n=s.size()/2;
    vector<int>v(2*n);
    map<int,set<int>>m;
    for(int i=0;i<2*n;i++){
        v[i]=s[i];
        m[v[i]].insert(i);
    }
    ll res=0,c=0;
    vector<int>s;
    for(int i=0;i<2*n;i++){
        if(v[i]==INT_MAX){
            continue;
        }
        if(v[i]>0){
            int j=*m[-v[i]].begin();
            v[j]=INT_MAX;
            int p1=(s.end()- lower_bound(all(s),i));
            int p2=(s.end()- lower_bound(all(s),j));
            s.pb(j);
            m[-v[i]].erase(m[-v[i]].begin());
            res+=(j-i-(p2-p1));
        }else{
            int j=*m[-v[i]].begin();
            v[j]=INT_MAX;
            int p1=(s.end()-lower_bound(all(s),i));
            int p2=(s.end()- lower_bound(all(s),j));
            s.pb(j);
            m[-v[i]].erase(m[-v[i]].begin());
            res+=(j-i-(p2-p1)-1);

        }
        m[v[i]].erase(i);
    }
    return res;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:53:16: error: declaration of 'std::vector<int> s' shadows a parameter
   53 |     vector<int>s;
      |                ^
shoes.cpp:43:40: note: 'std::vector<int> s' previously declared here
   43 | long long count_swaps(std::vector<int> s) {
      |                       ~~~~~~~~~~~~~~~~~^