Submission #314642

# Submission time Handle Problem Language Result Execution time Memory
314642 2020-10-20T14:06:12 Z amunduzbaev Sorting (IOI15_sorting) C++14
Compilation error
0 ms 0 KB
//#include "grader.cpp"
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a)
const int N=2*1e5+5;
int n, s[N], x[N], y[N];

vector<pair<int,int>>ans;
bool check(int m){
    int a[N], pos[N];
    for(int i=0;i<n;i++) a[i]=s[i];
    for(int i=0;i<m;i++) swap(a[x[i]], a[y[i]]);
    for(int i=0;i<n;i++) pos[a[i]]=i;

    vector<int> sx, sy;
    for(int i=0;i<n;i++){
        if(pos[i]!=i){
            int j=pos[i];
            sx.pb(a[i]);
            sy.pb(a[j]);
            pos[a[i]]=j;
            swap(a[i],a[j]);
        }
    }

    if(sx.size()>m) return false;
    ans.clear();

    for(int i=0;i<n;i++) a[i]=s[i], pos[a[i]]=i;
    for(int i=0;i<sx.size();i++){
        ans.pb({pos[sx[i]], pos[sy[i]]});
        int i1=pos[sx[i]],j1=pos[sy[i]];
        swap ( a[y[i]] ,a[y[i]] );
        swap ( a[i1], a[j1] );
        swap ( pos[a[x1]], pos[a[y1]] );
        swap ( pos[a[i1]], pos[a[j1]] );
    }
    for(int i=sx.size(); i<m; i++)
        ans.pb({0,0});
    return true;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    n=N;
    for(int i=0;i<n;i++) s[i]=S[i];
    for(int i=0;i<M;i++) x[i]=X[i], y[i]=Y[i];
    int l=0,r=M;
    while(l<r){
        int md=(l+r)/2;
        if(check(md)) r=md;
        else l=md+1;
    }
    for(int i=0;i<ans.size();i++){
        P[i]=ans[i].first;
        Q[i]=ans[i].second;
    }
	return l;

}


Compilation message

sorting.cpp:32:40: error: macro "pb" passed 2 arguments, but takes just 1
   32 |         ans.pb({pos[sx[i]], pos[sy[i]]});
      |                                        ^
sorting.cpp:5: note: macro "pb" defined here
    5 | #define pb(a) push_back(a)
      | 
sorting.cpp:40:21: error: macro "pb" passed 2 arguments, but takes just 1
   40 |         ans.pb({0,0});
      |                     ^
sorting.cpp:5: note: macro "pb" defined here
    5 | #define pb(a) push_back(a)
      | 
sorting.cpp: In function 'bool check(int)':
sorting.cpp:27:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     if(sx.size()>m) return false;
      |        ~~~~~~~~~^~
sorting.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<sx.size();i++){
      |                 ~^~~~~~~~~~
sorting.cpp:32:13: error: 'class std::vector<std::pair<int, int> >' has no member named 'pb'
   32 |         ans.pb({pos[sx[i]], pos[sy[i]]});
      |             ^~
sorting.cpp:36:22: error: 'x1' was not declared in this scope; did you mean 'j1'?
   36 |         swap ( pos[a[x1]], pos[a[y1]] );
      |                      ^~
      |                      j1
sorting.cpp:36:36: error: invalid types 'int [200005][double(double) throw () {aka double(double)}]' for array subscript
   36 |         swap ( pos[a[x1]], pos[a[y1]] );
      |                                    ^
sorting.cpp:39:22: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   39 |     for(int i=sx.size(); i<m; i++)
      |               ~~~~~~~^~
sorting.cpp:40:13: error: 'class std::vector<std::pair<int, int> >' has no member named 'pb'
   40 |         ans.pb({0,0});
      |             ^~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:44:76: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   44 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                                            ^
sorting.cpp:6:11: note: shadowed declaration is here
    6 | const int N=2*1e5+5;
      |           ^
sorting.cpp:54:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(int i=0;i<ans.size();i++){
      |                 ~^~~~~~~~~~~