Submission #1185707

#TimeUsernameProblemLanguageResultExecution timeMemory
1185707KerimSorting (IOI15_sorting)C++20
Compilation error
0 ms0 KiB
#include "sorting.h"
#include "bits/stdc++.h"

int f(int r, int n, int S[], int X[], int Y[], int p[], int q[]){
	int P[n], pos[n];
	for (int i = 0; i < n; i++)
		P[i] = S[i];
	//Ermek's first R swap operations
	for (int i = 0; i < r; i++)	
		swap(P[X[i]], P[Y[i]]);
	for (int i = 0; i < n; i++)
		pos[P[i]] = i;
	int r_prime = 0;
	for (int i = 0; i < n; i++){
		if (pos[i] == i)
			continue;
		int j = pos[i];
		p[r_prime] = P[i];
		q[r_prime] = P[j];
		r_prime += 1;
		swap(pos[P[i]], pos[P[j]]);
		swap(P[i], P[j]);
	}
	return r_prime;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	int r = 1;
    while (r <= M){
		if (f(r, N, S, X, Y, P, Q) <= r)
			break;
		r += 1;
	}
	assert(r <= M);
	int r_prime = f(r, N, S, X, Y, P, Q);
	int pos[N];
	for (int i = 0; i < N; i++)
		pos[S[i]] = i;
	for (int i = 0; i < r_prime; i++){
		swap(pos[S[X[i]]], pos[S[Y[i]]]);
		swap(S[X[i]], S[Y[i]]);
		int p = pos[P[i]], q = pos[Q[i]];
		swap(pos[S[p]], pos[S[q]]);
		swap(S[p], S[q]);
		P[i] = p;
		Q[i] = q;
	}
	for (int i = r_prime; i < r; i++)
		P[i] = Q[i] = 0;
	return r;
}


Compilation message (stderr)

sorting.cpp: In function 'int f(int, int, int*, int*, int*, int*, int*)':
sorting.cpp:10:17: error: 'swap' was not declared in this scope
   10 |                 swap(P[X[i]], P[Y[i]]);
      |                 ^~~~
sorting.cpp:10:17: note: suggested alternatives:
In file included from /usr/include/c++/11/regex:63,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:110,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/regex.h:2165:5: note:   'std::__cxx11::swap'
 2165 |     swap(match_results<_Bi_iter, _Alloc>& __lhs,
      |     ^~~~
In file included from /usr/include/c++/11/bits/stl_pair.h:59,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/move.h:196:5: note:   'std::swap'
  196 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/11/bits/move.h:196:5: note:   'std::swap'
In file included from /usr/include/c++/11/compare:39,
                 from /usr/include/c++/11/bits/stl_pair.h:65,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from sorting.cpp:2:
/usr/include/c++/11/concepts:227:43: note:   'std::ranges::__cust::swap'
  227 |       inline constexpr __cust_swap::_Swap swap{};
      |                                           ^~~~
In file included from /usr/include/c++/11/exception:153,
                 from /usr/include/c++/11/ios:39,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/exception_ptr.h:223:5: note:   'std::__exception_ptr::swap'
  223 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
In file included from /usr/include/c++/11/filesystem:45,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:129,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/fs_path.h:692:15: note:   'std::filesystem::__cxx11::swap'
  692 |   inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
      |               ^~~~
In file included from /usr/include/c++/11/compare:39,
                 from /usr/include/c++/11/bits/stl_pair.h:65,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from sorting.cpp:2:
/usr/include/c++/11/concepts:167:35: note:   'std::ranges::__cust_swap::swap'
  167 |       template<typename _Tp> void swap(_Tp&, _Tp&) = delete;
      |                                   ^~~~
sorting.cpp:21:17: error: 'swap' was not declared in this scope
   21 |                 swap(pos[P[i]], pos[P[j]]);
      |                 ^~~~
sorting.cpp:21:17: note: suggested alternatives:
In file included from /usr/include/c++/11/regex:63,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:110,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/regex.h:2165:5: note:   'std::__cxx11::swap'
 2165 |     swap(match_results<_Bi_iter, _Alloc>& __lhs,
      |     ^~~~
In file included from /usr/include/c++/11/bits/stl_pair.h:59,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/move.h:196:5: note:   'std::swap'
  196 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/11/bits/move.h:196:5: note:   'std::swap'
In file included from /usr/include/c++/11/compare:39,
                 from /usr/include/c++/11/bits/stl_pair.h:65,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from sorting.cpp:2:
/usr/include/c++/11/concepts:227:43: note:   'std::ranges::__cust::swap'
  227 |       inline constexpr __cust_swap::_Swap swap{};
      |                                           ^~~~
In file included from /usr/include/c++/11/exception:153,
                 from /usr/include/c++/11/ios:39,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/exception_ptr.h:223:5: note:   'std::__exception_ptr::swap'
  223 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
In file included from /usr/include/c++/11/filesystem:45,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:129,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/fs_path.h:692:15: note:   'std::filesystem::__cxx11::swap'
  692 |   inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
      |               ^~~~
In file included from /usr/include/c++/11/compare:39,
                 from /usr/include/c++/11/bits/stl_pair.h:65,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from sorting.cpp:2:
/usr/include/c++/11/concepts:167:35: note:   'std::ranges::__cust_swap::swap'
  167 |       template<typename _Tp> void swap(_Tp&, _Tp&) = delete;
      |                                   ^~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:39:17: error: 'swap' was not declared in this scope
   39 |                 swap(pos[S[X[i]]], pos[S[Y[i]]]);
      |                 ^~~~
sorting.cpp:39:17: note: suggested alternatives:
In file included from /usr/include/c++/11/regex:63,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:110,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/regex.h:2165:5: note:   'std::__cxx11::swap'
 2165 |     swap(match_results<_Bi_iter, _Alloc>& __lhs,
      |     ^~~~
In file included from /usr/include/c++/11/bits/stl_pair.h:59,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/move.h:196:5: note:   'std::swap'
  196 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/11/bits/move.h:196:5: note:   'std::swap'
In file included from /usr/include/c++/11/compare:39,
                 from /usr/include/c++/11/bits/stl_pair.h:65,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from sorting.cpp:2:
/usr/include/c++/11/concepts:227:43: note:   'std::ranges::__cust::swap'
  227 |       inline constexpr __cust_swap::_Swap swap{};
      |                                           ^~~~
In file included from /usr/include/c++/11/exception:153,
                 from /usr/include/c++/11/ios:39,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/exception_ptr.h:223:5: note:   'std::__exception_ptr::swap'
  223 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
In file included from /usr/include/c++/11/filesystem:45,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:129,
                 from sorting.cpp:2:
/usr/include/c++/11/bits/fs_path.h:692:15: note:   'std::filesystem::__cxx11::swap'
  692 |   inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
      |               ^~~~
In file included from /usr/include/c++/11/compare:39,
                 from /usr/include/c++/11/bits/stl_pair.h:65,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from sorting.cpp:2:
/usr/include/c++/11/concepts:167:35: note:   'std::ranges::__cust_swap::swap'
  167 |       template<typename _Tp> void swap(_Tp&, _Tp&) = delete;
      |                                   ^~~~