Submission #307482

# Submission time Handle Problem Language Result Execution time Memory
307482 2020-09-28T10:10:57 Z lohacho Sorting (IOI15_sorting) C++14
Compilation error
0 ms 0 KB
#include "sorting.h"
#include <bits/stdc++.h>

using namespace std;

using LL = long long;
const int INF = (int)1e9 + 7;
const int NS = (int)2e5 + 4;
int mov[NS], index[NS], pos[NS], S_save[NS];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    for(int i = 0; i < N; ++i){
        S_save[i] = S[i];
    }
    int low = 0, high = N - 1, mid;
    function < int() > can_sort = [&](){
        for(int i = 0; i < N; ++i){
            S[i] = S_save[i];
            mov[i] = i; index[i] = i;
            pos[S[i]] = i;
        }
        for(int i = mid - 1; i >= 0; --i){
            swap(mov[X[i]], mov[Y[i]]);
        }
        int diff = 0;
        for(int i = 0; i < mid; ++i){
            while(diff < N && mov[diff] == S[diff]) ++diff;
            swap(index[X[i]], index[Y[i]]);
            if(diff >= N){
                P[i] = Q[i] = 0;
            }
            else{
                P[i] = index[diff], Q[i] = index[pos[mov[diff]]];
                swap(index[diff], index[pos[mov[diff]]]);
                swap(S[diff], S[pos[mov[diff]]]);
            }
        }
        while(diff < N && mov[diff] == S[diff]) ++diff;
        if(diff >= N) return 1;
        else return 0;
    };
    while(low < high){
        mid = (low + high) >> 1;
        for(int i = 0; i < N; ++i) P[i] = Q[i] = 0;
        if(can_sort()){
            high = mid;
        }
        else{
            low = mid + 1;
        }
    }
    return low;
}


Compilation message

sorting.cpp:9:22: error: 'int index [200004]' redeclared as different kind of entity
    9 | int mov[NS], index[NS], pos[NS], S_save[NS];
      |                      ^
In file included from /usr/include/c++/9/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:48,
                 from sorting.cpp:2:
/usr/include/string.h:477:1: note: previous declaration 'const char* index(const char*, int)'
  477 | index (const char *__s, int __c) __THROW
      | ^~~~~
sorting.cpp: In lambda function:
sorting.cpp:19:32: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   19 |             mov[i] = i; index[i] = i;
      |                                ^
sorting.cpp:28:28: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   28 |             swap(index[X[i]], index[Y[i]]);
      |                            ^
sorting.cpp:28:41: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   28 |             swap(index[X[i]], index[Y[i]]);
      |                                         ^
sorting.cpp:33:34: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   33 |                 P[i] = index[diff], Q[i] = index[pos[mov[diff]]];
      |                                  ^
sorting.cpp:33:64: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   33 |                 P[i] = index[diff], Q[i] = index[pos[mov[diff]]];
      |                                                                ^
sorting.cpp:34:32: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   34 |                 swap(index[diff], index[pos[mov[diff]]]);
      |                                ^
sorting.cpp:34:55: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   34 |                 swap(index[diff], index[pos[mov[diff]]]);
      |                                                       ^
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:11:39: warning: unused parameter 'M' [-Wunused-parameter]
   11 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^