Submission #712133

# Submission time Handle Problem Language Result Execution time Memory
712133 2023-03-18T07:48:41 Z neki Sorting (IOI15_sorting) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "sorting.h"
#define vc vector
 
using namespace std;
 
int findSwapPairs(int n, int s[], int m, int x[], int y[], int a[], int b[])
{
    int is[n];for(int i=0;i<n;++i) is[s[i]]=i;
    
    function<bool (int)> solve=[&](int x){
        int p[n], ip[n], z[n], iz[n];
        for(int i=0;i<n;++i) p[i]=i, z[i]=iz[i]=i;
        for(int i=x;i>=0;--i) swap(p[x[i]], p[y[i]]);
		for(int i=0;i<n;++i) ip[p[i]]=i;
        
        for(int i=x;i>=0;--i){
            while(j<n && j==s[p[iz[j]]]) ++j;
            if(j<n) a[i]=iz[j], b[i]=ip[is[j]];
            else a[i]=b[i]=0;
            
            swap(ip[p[x[i]]], ip[p[y[i]]]);
            swap(p[x[i]], p[y[i]]);
            
            swap(iz[z[a[i]]], iz[z[b[i]]]);
            swap(z[a[i]], z[b[i]]);
            swap(iz[z[x[i]]], iz[z[y[i]]]);
            swap(z[x[i]], z[y[i]]);
        }
        return j==n;
    }
    
    int l=0, r=m-1;
    while(l<r){
        int mid=(l+r)/2, j=0;
        
        if(solve(mid)) r=mid;
        else l=mid+1;
    }
    solve(l);
    
    return l;
}

Compilation message

sorting.cpp: In lambda function:
sorting.cpp:11:40: warning: declaration of 'int x' shadows a parameter [-Wshadow]
   11 |     function<bool (int)> solve=[&](int x){
      |                                    ~~~~^
sorting.cpp:7:46: note: shadowed declaration is here
    7 | int findSwapPairs(int n, int s[], int m, int x[], int y[], int a[], int b[])
      |                                          ~~~~^~~
sorting.cpp:14:39: error: invalid types 'int[int]' for array subscript
   14 |         for(int i=x;i>=0;--i) swap(p[x[i]], p[y[i]]);
      |                                       ^
sorting.cpp:18:19: error: 'j' was not declared in this scope
   18 |             while(j<n && j==s[p[iz[j]]]) ++j;
      |                   ^
sorting.cpp:19:16: error: 'j' was not declared in this scope
   19 |             if(j<n) a[i]=iz[j], b[i]=ip[is[j]];
      |                ^
sorting.cpp:22:24: error: invalid types 'int[int]' for array subscript
   22 |             swap(ip[p[x[i]]], ip[p[y[i]]]);
      |                        ^
sorting.cpp:23:21: error: invalid types 'int[int]' for array subscript
   23 |             swap(p[x[i]], p[y[i]]);
      |                     ^
sorting.cpp:27:24: error: invalid types 'int[int]' for array subscript
   27 |             swap(iz[z[x[i]]], iz[z[y[i]]]);
      |                        ^
sorting.cpp:28:21: error: invalid types 'int[int]' for array subscript
   28 |             swap(z[x[i]], z[y[i]]);
      |                     ^
sorting.cpp:30:16: error: 'j' was not declared in this scope
   30 |         return j==n;
      |                ^
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:31:5: error: conversion from 'findSwapPairs(int, int*, int, int*, int*, int*, int*)::<lambda(int)>' to non-scalar type 'std::function<bool(int)>' requested
   31 |     }
      |     ^
sorting.cpp:34:11: error: 'l' was not declared in this scope
   34 |     while(l<r){
      |           ^
sorting.cpp:34:13: error: 'r' was not declared in this scope
   34 |     while(l<r){
      |             ^
sorting.cpp:40:11: error: 'l' was not declared in this scope
   40 |     solve(l);
      |           ^
sorting.cpp:7:39: warning: unused parameter 'm' [-Wunused-parameter]
    7 | int findSwapPairs(int n, int s[], int m, int x[], int y[], int a[], int b[])
      |                                   ~~~~^
sorting.cpp:7:46: warning: unused parameter 'x' [-Wunused-parameter]
    7 | int findSwapPairs(int n, int s[], int m, int x[], int y[], int a[], int b[])
      |                                          ~~~~^~~