Submission #317926

# Submission time Handle Problem Language Result Execution time Memory
317926 2020-10-30T20:26:03 Z keta_tsimakuridze Sorting (IOI15_sorting) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "sorting.h"
using namespace std;
int findSwapPairs(int N, int A[], int M, int x[], int y[], int P[], int Q[]) {
    int l=3; int r=3;
    std::vector<std::pair<int,int> > V,ans;
    int a[N+5],ind[N+5];
    while(l<=r){
    	V.clear();
    	int mid=(l+r)/2;
    	for(int i=0;i<N;i++){
    		ind[A[i]]=i;
    		a[i]=A[i];
		}
		for(int i=0;i<mid;i++){
			std::swap(a[x[i]],a[y[i]]);
		}
		for(int i=0;i<N;i++){
			ind[a[i]]=i;
		}	
		
		for(int i=0;i<N;i++){
			if(a[i]!=i){
			V.push_back(std::make_pair(a[i],i));
				std::swap(a[i],a[ind[i]]);		
				std::swap(ind[a[ind[i]]],ind[i]);	
			}
		}
	
		for(int i=0;i<N;i++){
			a[i]=A[i];
			ind[a[i]]=i;
		}
		if(V.size()<=mid) {
			ans.clear(); 
			for(int i=0;i<mid;i++){
			std::swap(ind[a[x[i]]],ind[a[y[i]]]);
			std::swap(a[x[i]],a[y[i]]);
			if(i<V.size() ){
				// V[i].f V[i].s 
				swap(ind[V[i].f],ind[V[i].s]);
				swap(a[ind[V[i].f]],a[ind[V[i].s]]);
				ans.push_back({ind[V[i].f],ind[V[i].s]});
			}
			else ans.push_back({0,0});
		}
			
			r=mid-1;
		}
		else l=mid+1;
	} 
	for(int i=0;i<ans.size();i++){
	P[i]=ans[i].first;
	Q[i]=ans[i].second;
	}
	return ans.size();
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:34:14: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |   if(V.size()<=mid) {
      |      ~~~~~~~~^~~~~
sorting.cpp:39:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |    if(i<V.size() ){
      |       ~^~~~~~~~~
sorting.cpp:41:19: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'f'
   41 |     swap(ind[V[i].f],ind[V[i].s]);
      |                   ^
sorting.cpp:41:31: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 's'
   41 |     swap(ind[V[i].f],ind[V[i].s]);
      |                               ^
sorting.cpp:42:21: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'f'
   42 |     swap(a[ind[V[i].f]],a[ind[V[i].s]]);
      |                     ^
sorting.cpp:42:36: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 's'
   42 |     swap(a[ind[V[i].f]],a[ind[V[i].s]]);
      |                                    ^
sorting.cpp:43:29: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'f'
   43 |     ans.push_back({ind[V[i].f],ind[V[i].s]});
      |                             ^
sorting.cpp:43:41: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 's'
   43 |     ans.push_back({ind[V[i].f],ind[V[i].s]});
      |                                         ^
sorting.cpp:43:44: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   43 |     ans.push_back({ind[V[i].f],ind[V[i].s]});
      |                                            ^
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from sorting.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1184: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>]'
 1184 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1184:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1184 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1200: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>]'
 1200 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1200:30: 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>&&'}
 1200 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
sorting.cpp:52:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int i=0;i<ans.size();i++){
      |              ~^~~~~~~~~~~
sorting.cpp:56:17: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   56 |  return ans.size();
      |         ~~~~~~~~^~
sorting.cpp:4:39: warning: unused parameter 'M' [-Wunused-parameter]
    4 | int findSwapPairs(int N, int A[], int M, int x[], int y[], int P[], int Q[]) {
      |                                   ~~~~^