Submission #1240186

#TimeUsernameProblemLanguageResultExecution timeMemory
1240186simplemind_31Sorting (IOI15_sorting)C++20
Compilation error
0 ms0 KiB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
int n;
vector<int> ss, x, y;
vector<pii> ans;

bool check(int m){
	ans.assign(m,{0,0});
	vector<int> plates(n),id(n),s(n),b(n),bid(n);
	for (int i=0;i<n;i++){
		s[i]=ss[i];
		plates[i]=i;
		id[s[i]]=i;
	}
	for (int i=0;i<m;i++){
		swap(plates[x[i]], plates[y[i]]);
	}
	for (int i=0;i<n;i++){
		b[plates[i]]=i;
		bid[b[plates[i]]]=i;
	}
	for (int i=0;i<n;i++){
		bid[b[i]]=i;
	}
	int p=0;
	for (int i=0; i<m; ++i){
		swap(s[x[i]], s[y[i]]);
		swap(b[x[i]], b[y[i]]);
		id[s[x[i]]]=x[i];
		id[s[y[i]]]=y[i];
		bid[b[x[i]]]=x[i];
		bid[b[y[i]]]=y[i];
		while (p<n&&id[p]==bid[p])++p;
		if (p==n)break;
		pii temp ={id[p],bid[p]};
		swap(s[temp.first], s[temp.second]);
		id[s[temp.first]]=temp.first;
		id[s[temp.second]]=temp.second;
		ans[i]=temp;
	}
	while (p<n&&id[p]==bid[p])++p;
	return p==n;
}
int findSwapPairs(int N,int S[],int m,int X[],int Y[],int p[],int q[]){
	n=N;
	ss.assign(n,0);
	x.assign(m,0);
	y.assign(m,0);
	for(int i=0;i<n;i++){
		{
		ss[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 mid=(l+r)>>1;
		if(check(mid)){
			r=mid;
		}else{
			l=mid+1;
		}
	}
	check(l);
	for(int i=0;i<l;i++){
		{
		p[i]=ans[i].first;
		q[i]=ans[i].second;
	}
	return l;
}

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:77:2: error: expected '}' at end of input
   77 | }
      |  ^
sorting.cpp:56:30: note: to match this '{'
   56 |         for(int i=0; i<m;i++){
      |                              ^
sorting.cpp:77:2: error: expected '}' at end of input
   77 | }
      |  ^
sorting.cpp:52:29: note: to match this '{'
   52 |         for(int i=0;i<n;i++){
      |                             ^
sorting.cpp:77:2: error: expected '}' at end of input
   77 | }
      |  ^
sorting.cpp:47:71: note: to match this '{'
   47 | int findSwapPairs(int N,int S[],int m,int X[],int Y[],int p[],int q[]){
      |                                                                       ^
sorting.cpp:77:2: warning: control reaches end of non-void function [-Wreturn-type]
   77 | }
      |  ^