Submission #252173

#TimeUsernameProblemLanguageResultExecution timeMemory
252173HeheheSorting (IOI15_sorting)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#include "sorting.h"

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 2e9;
const ll mod = 1e9 + 9;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

//ifstream in(".in");
//ofstream out(".out");


int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {

    int n = N, m = M;

    for(int i = 0; i < n; i++){
        pos[S[i]] = i;
    }

    vector<pi>ans;
    for(int i = 0; i < n; i++){
        if(S[i] == i)continue;
        ans.push_back({i, pos[i]});
        int x = S[i], y = S[pos[i]];
        swap(S[i], S[pos[i]]);
        pos[y] = i;
        pos[x] = x;
    }

    int k = 0;
    for(auto it : ans){
        P[k] = it.ff;
        Q[k] = it.ss;
        k++;
    }

    return sz(ans);
}

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:32:9: error: 'pos' was not declared in this scope
         pos[S[i]] = i;
         ^~~
sorting.cpp:32:9: note: suggested alternative: 'pow'
         pos[S[i]] = i;
         ^~~
         pow
sorting.cpp:38:27: error: 'pos' was not declared in this scope
         ans.push_back({i, pos[i]});
                           ^~~
sorting.cpp:38:27: note: suggested alternative: 'pow'
         ans.push_back({i, pos[i]});
                           ^~~
                           pow
sorting.cpp:38:34: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
         ans.push_back({i, pos[i]});
                                  ^
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:1:
/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<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:939:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<int, int>&}'
/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<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:953:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&& {aka std::pair<int, int>&&}'
sorting.cpp:29:16: warning: unused variable 'm' [-Wunused-variable]
     int n = N, m = M;
                ^
sorting.cpp:27:48: warning: unused parameter 'X' [-Wunused-parameter]
 int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
                                                ^
sorting.cpp:27:57: warning: unused parameter 'Y' [-Wunused-parameter]
 int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
                                                         ^