# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
138249 |
2019-07-29T16:17:32 Z |
MvC |
Sorting (IOI15_sorting) |
C++11 |
|
3 ms |
504 KB |
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#include "sorting.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e6+50;
const int mod=1e9+7;
using namespace std;
int s[nmax],x[nmax],y[nmax],p[nmax],px[nmax],py[nmax],cr[nmax],i,n,m,ss[nmax],vl[nmax];
//int rx[nmax],ry[nmax];
/*int findSwapPairs(int N,int S[],int M,int X[],int Y[],int rx[],int ry[])
{
n=N,m=M;
for(i=0;i<n;i++)s[i]=S[i];
for(i=0;i<m;i++)
{
x[i]=X[i];
y[i]=Y[i];
}
for(i=0;i<n;i++)
{
p[i]=i;
px[s[i]]=i;
py[i]=i;
ss[i]=s[i];
vl[i]=s[i];
cr[i]=i;
}
for(i=0;i<n;i++)
{
swap(p[x[i]],p[y[i]]);
rx[i]=ry[i]=0;
}
for(i=0;i<n;i++)
{
swap(py[x[i]],py[y[i]]);
cr[py[x[i]]]=x[i];
cr[py[y[i]]]=y[i];
rx[i]=cr[p[i]];
ry[i]=cr[px[i]];
swap(px[i],px[ss[p[i]]]);
swap(ss[px[ss[p[i]]]],ss[p[i]]);
}
return n;
}*/
int findSwapPairs(int N,int S[],int M,int X[],int Y[],int rx[],int ry[])
{
n=N,m=M;
for(i=0;i<n;i++)s[i]=S[i];
for(i=0;i<m;i++)
{
x[i]=X[i];
y[i]=Y[i];
}
for(i=0;i<n;i++)
{
p[s[i]]=i;
}
int j=0;
for(i=0;i<n;i++)
{
rx[j]=p[i];
ry[j]=i;
j++;
if(i==p[i])continue;
swap(s[i],s[p[i]]);
swap(p[s[i]],p[s[p[i]]]);
}
return j;
}
/*
7 7
0 5 3 6 1 2 4
0 0
0 0
0 0
0 0
0 0
0 0
0 0
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>m;
for(i=0;i<n;i++)cin>>s[i];
for(i=0;i<m;i++)cin>>x[i]>>y[i];
for(i=0;i<n;i++)
{
p[s[i]]=i;
}
for(i=0;i<n;i++)
{
//swap(s[x[i]],s[y[i]]);
//p[s[x[i]]]=x[i];
//p[s[y[i]]]=y[i];
rx[i]=p[i];
ry[i]=i;
cout<<rx[i]<<" "<<ry[i]<<endl;
swap(s[i],s[p[i]]);
swap(p[s[i]],p[s[p[i]]]);
}
for(i=0;i<n;i++)cout<<s[i]<<" ";
cout<<endl;
return 0;
}
/*int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>m;
for(i=0;i<n;i++)cin>>s[i];
for(i=0;i<m;i++)cin>>x[i]>>y[i];
for(i=0;i<n;i++)
{
p[i]=i;
px[s[i]]=i;
py[i]=i;
ss[i]=s[i];
vl[i]=s[i];
cr[i]=i;
}
for(i=0;i<n;i++)
{
swap(p[x[i]],p[y[i]]);
}
cout<<endl;
for(i=0;i<n;i++)cout<<p[i]<<" ";
cout<<endl;
for(i=0;i<n;i++)
{
swap(py[x[i]],py[y[i]]);
swap(vl[x[i]],vl[y[i]]);
cr[py[x[i]]]=x[i];
cr[py[y[i]]]=y[i];
// p[i] - cr[p[i]] , px[i] cr[px[i]]
rx[i]=cr[p[i]];
ry[i]=cr[px[i]];
swap(vl[cr[p[i]]],vl[cr[px[i]]]);
cout<<cr[p[i]]<<" "<<cr[px[i]]<<endl;
swap(px[i],px[ss[p[i]]]);
swap(ss[px[ss[p[i]]]],ss[p[i]]);
}
cout<<endl;
for(i=0;i<n;i++)cout<<vl[i]<<" ";
cout<<endl;
return 0;
}
/*
5 6
4 3 2 1 0
0 1
1 2
2 3
3 4
0 1
1 2
5 5
3 0 4 2 1
1 1
4 0
2 3
1 4
0 4
*/
Compilation message
sorting.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
sorting.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
sorting.cpp:123:1: warning: "/*" within comment [-Wcomment]
/*int main()
sorting.cpp:167:1: warning: "/*" within comment [-Wcomment]
/*
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |