Submission #540464

#TimeUsernameProblemLanguageResultExecution timeMemory
540464new_accArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h"
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef unsigned long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int M=1e6+10;
const int N=1e5+10;
const int SS=1<<20;
const int INFi=1e9;
const ll INFl=1e12;
int val[N],t[N],seg[(SS<<1)+1],wsk[N];
bitset<N>vis;
vi g[N];
void upd(int a,int ind){
    for(ind+=SS;ind>0;ind>>=1) seg[ind]+=a;
}
int Query(int a,int b){
    int res=0;
    for(a+=SS-1,b+=SS+1;(a>>1)!=(b>>1);a>>=1,b>>=1){
        if(!(a&1)) res+=seg[a+1];
        if(b&1) res+=seg[b-1];
    }
    return res;
}
ll count_swaps(vi v){
    int n=v.size();
    for(int i=0;i<v.size();i++) t[i+1]=v[i];
    for(int i=1;i<=n;i++)
        if(t[i]>0) g[t[i]].push_back(i);
    for(int i=1;i<=n;i++){
        if(t[i]>0) continue;
        int curr=t[i]*(-1);
        int m=g[curr][wsk[curr]++];
        val[m]=(min(m,i)<<1)+1,val[i]=(min(m,i)<<1);
        vis[max(m,i)]=1;
    }
    ll res=0;
    for(int i=1;i<=n;i++){
        upd(1,val[i]);
        if(vis[i]) res+=(ll)Query(val[i]+1,(n<<1));
    }
    return res;
}

Compilation message (stderr)

shoes.cpp:29:4: error: ambiguating new declaration of 'll count_swaps(vi)'
   29 | ll count_swaps(vi v){
      |    ^~~~~~~~~~~
In file included from shoes.cpp:1:
shoes.h:7:11: note: old declaration 'long long int count_swaps(std::vector<int>)'
    7 | long long count_swaps(std::vector<int> S);
      |           ^~~~~~~~~~~
shoes.cpp: In function 'll count_swaps(vi)':
shoes.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i=0;i<v.size();i++) t[i+1]=v[i];
      |                 ~^~~~~~~~~