Submission #316000

# Submission time Handle Problem Language Result Execution time Memory
316000 2020-10-24T19:04:35 Z semiauto Sorting (IOI15_sorting) C++
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
const int N=5000000;
int n,i,mas1[N],k,m,num1[N],mas[N],num[N],killer,ans1[N],ans2[N],ans,a[N],b[N];
int main()
	{
	cin>>n;
	for (i=0;i<n;i++)
		{
		scanf("%d",&mas[i]);
		num[mas[i]]=i;
		num1[mas[i]]=i;
		mas1[i]=mas[i];
		}
	cin>>m;
	for (killer=1;killer<=m;killer++)
			{
			scanf("%d",&a[k]);scanf("%d",&b[k]);
			swap(mas[a[k]],mas[b[k]]);
			swap(num[mas[a[k]]],num[mas[b[k]]]);k++;
			}
	for (i=0;i<n;i++)
		if (mas[i]!=i)
			{
			ans1[ans]=i;
			ans2[ans]=mas[i];
			swap(mas[i],mas[num[i]]);
			swap(num[mas[i]],num[mas[num[i]]]);
			ans++;
			}
	cout<<m<<endl;
	for (i=0;i<n;i++){mas[i]=mas1[i];num[i]=num1[i];
	}
	for (i=0;i<m;i++)
		{
		swap(mas[a[i]],mas[b[i]]);
		swap(num[mas[a[i]]],num[mas[b[i]]]);
		printf("%d %d\n",num[ans1[i]],num[ans2[i]]);
		//cout<<num[ans1[i]]<<" "<<num[ans2[i]]<<endl;
		swap(mas[num[ans1[i]]],mas[num[ans2[i]]]);
		swap(num[mas[num[ans1[i]]]],num[mas[num[ans2[i]]]]);
		}
	return 0;
	}

Compilation message

sorting.cpp: In function 'int main()':
sorting.cpp:10:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |   scanf("%d",&mas[i]);
      |   ~~~~~^~~~~~~~~~~~~~
sorting.cpp:18:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |    scanf("%d",&a[k]);scanf("%d",&b[k]);
      |    ~~~~~^~~~~~~~~~~~
sorting.cpp:18:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |    scanf("%d",&a[k]);scanf("%d",&b[k]);
      |                      ~~~~~^~~~~~~~~~~~
/tmp/cchttaQ6.o: In function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'
/tmp/ccqEKLfT.o:sorting.cpp:(.text.startup+0x0): first defined here
/tmp/cchttaQ6.o: In function `main':
grader.c:(.text.startup+0x4a5): undefined reference to `findSwapPairs(int, int*, int, int*, int*, int*, int*)'
collect2: error: ld returned 1 exit status