Submission #60171

#TimeUsernameProblemLanguageResultExecution timeMemory
60171Flugan42Sorting (IOI15_sorting)C++14
Compilation error
0 ms0 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<ll> vi; typedef pair<ll,ll> ii; typedef vector<ii> vii; #define rep(i,a,b) for(int i = a; i < b; i++) #define per(i,a,b) for(int i = a; i >= b; i--) #define inf 9223372036854775807 #define all(x) x.begin(),x.end() #define sz(x) (ll)(x).size() #define trav(a,x) for(auto& a : x) int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { ll lo = -1, hi = N, mid; while (lo+1 < hi){ mid = (lo+hi)/2; vi last; last.assign(N,0); rep(i,0,N) last[i] = S[i]; rep(i,0,mid){ ll t1 = last[X[i]]; ll t2 = last[Y[i]]; last[Y[i]] = t1; last[X[i]] = t2; } vi inv; inv.assign(N,0); rep(i,0,N) inv[last[i]] = i; ll cur = 0; rep(i,0,mid){ while (cur < N && inv[cur] == cur) cur++; if (cur == N) break; ll s = last[cur],ls = inv[cur]; last[ls] = s; last[cur] = cur; inv[cur] = cur; inv[s] = ls; } if (inv[N-1] != N-1) { lo = mid; } else { hi = mid; } } vii swap; vi last; last.assign(N,0); rep(i,0,N) last[i] = S[i]; rep(i,0,hi){ ll t1 = last[X[i]]; ll t2 = last[Y[i]]; last[Y[i]] = t1; last[X[i]] = t2; } vi inv; inv.assign(N,0); rep(i,0,N) inv[last[i]] = i; ll cur = 0; vii swap; rep(i,0,hi){ while (cur < N && inv[cur] == cur) cur++; if (cur == N) break; ll s = last[cur],ls = inv[cur]; swap.push_back(s,cur); last[ls] = s; last[cur] = cur; inv[cur] = cur; inv[s] = ls; } while (sz(swap) < hi) swap.push_back(make_pair(0,0)); last.assign(N,0); inv.assign(N,0); rep(i,0,N) last[i] = S[i]; rep(i,0,N) inv[last[i]] = i; rep(i,0,hi){ ll t1 = last[X[i]]; ll t2 = last[Y[i]]; last[Y[i]] = t1; last[X[i]] = t2; inv[t1] = Y[i]; inv[t2] = X[i]; // P[i] = inv[swap[i].first]; Q[i] = inv[swap[i].second]; last[P[i]] = swap[i].second; last[Q[i]] = swap[i].first; inv[swap[i].first] = Q[i]; inv[swap[i].second] = P[i]; } return hi; }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:58:7: error: redeclaration of 'vii swap'
   vii swap;
       ^~~~
sorting.cpp:46:7: note: 'vii swap' previously declared here
   vii swap;
       ^~~~
sorting.cpp:63:25: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(ll&, ll&)'
     swap.push_back(s,cur);
                         ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from sorting.cpp:2:
/usr/include/c++/7/bits/stl_vector.h:939:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:939:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/7/bits/stl_vector.h:953:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:953:7: note:   candidate expects 1 argument, 2 provided
sorting.cpp:82:29: warning: conversion to 'int' from '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}' may alter its value [-Wconversion]
     P[i] = inv[swap[i].first];
                             ^
sorting.cpp:83:30: warning: conversion to 'int' from '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}' may alter its value [-Wconversion]
     Q[i] = inv[swap[i].second];
                              ^
sorting.cpp:89:9: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return hi;
         ^~
sorting.cpp:16:39: warning: unused parameter 'M' [-Wunused-parameter]
 int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
                                       ^