QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#473073#2789. SortingRafi228 1ms4104kbC++141.9kb2024-07-11 21:36:322024-07-11 21:36:32

Judging History

你现在查看的是最新测评结果

  • [2024-07-11 21:36:32]
  • 评测
  • 测评结果:8
  • 用时:1ms
  • 内存:4104kb
  • [2024-07-11 21:36:32]
  • 提交

answer

#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)
int inf=2000000007;
ll infl=1000000000000000007;
ll mod=1000000007;



int findSwapPairs(int n, int S[], int m, int X[], int Y[], int P[], int Q[])
{
	bool ok=1;
	FOR(i,0,n-1) ok&=(S[i]==i);
	if(ok) return 0;
    int l=1,r=m,sr,ans=m;
    while(l<=r)
    {
		vector<int>ord(n),p(n),pos(n),odw(n,0);
		FOR(i,0,n-1) 
		{
			ord[i]=i;
			pos[i]=i;
		}
		sr=(l+r)/2;
		FOR(i,0,sr-1) swap(pos[X[i]],pos[Y[i]]); 
		FOR(i,0,n-1) ord[pos[i]]=i;
		FOR(i,0,n-1) p[S[i]]=ord[i];
		FOR(i,0,n-1) debug(p[i]);
		FOR(i,0,n-1) debug(ord[i]);
		vector<pair<int,int>>res;
		FOR(i,0,n-1)
		{
			if(odw[i]) continue;
			int x=i;
			vector<int>V;
			while(!odw[x])
			{
				if(x!=i) V.pb(x);
				debug(i,x);
				odw[x]=1;
				x=p[x];
			}
			for(auto j:V) res.pb({i,j});
		}
		if(sz(res)<=sr)
		{
			ans=sr;
			r=sr-1;
			FOR(i,0,sr-1)
			{
				P[i]=res[i].st;
				Q[i]=res[i].nd;
			}
		}
		else l=sr+1;
	}
	debug(ans);
	vector<int>pos(n);
	FOR(i,0,n-1) pos[S[i]]=i;
	FOR(i,0,ans-1) 
	{
		P[i]=pos[P[i]];
		Q[i]=pos[Q[i]];
		swap(pos[S[P[i]]],pos[S[Q[i]]]);
		swap(S[P[i]],S[Q[i]]);
		swap(pos[S[X[i]]],pos[S[Y[i]]]);
		swap(S[X[i]],S[Y[i]]);
	}
	FOR(i,0,n-1) debug(S[i]);
	return ans;
}



詳細信息

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 0ms
memory: 3740kb

input:

1
0
1
0 0

output:

0

result:

ok correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 4104kb

input:

2
0 1
4
0 0
0 0
0 0
0 0

output:

0

result:

ok correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 4032kb

input:

2
1 0
4
0 0
0 0
0 0
0 0

output:

1
1 0

result:

ok correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

3
1 0 2
9
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

1
1 0

result:

ok correct

Test #5:

score: 0
Accepted
time: 0ms
memory: 4028kb

input:

4
3 2 0 1
16
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

3
2 1
1 3
3 0

result:

ok correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 3752kb

input:

5
1 4 2 3 0
25
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

2
4 1
1 0

result:

ok correct

Test #7:

score: 0
Accepted
time: 1ms
memory: 4032kb

input:

5
4 2 1 0 3
25
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

3
3 4
4 0
2 1

result:

ok correct

Subtask #2:

score: 0
Runtime Error

Test #8:

score: 12
Accepted
time: 0ms
memory: 3800kb

input:

1
0
30
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

0

result:

ok correct

Test #9:

score: 0
Accepted
time: 0ms
memory: 4032kb

input:

2
0 1
60
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

0

result:

ok correct

Test #10:

score: -12
Runtime Error

input:

98
82 70 31 12 27 51 84 90 66 8 49 52 74 91 46 7 96 67 63 85 34 50 87 83 58 78 26 39 77 48 2 55 94 25 61 56 53 13 32 86 72 20 37 73 9 93 65 28 18 11 71 59 88 35 76 40 24 36 33 3 17 29 38 5 21 15 79 30 62 92 45 80 64 95 43 75 97 23 16 57 22 60 41 69 0 42 14 10 47 68 19 4 1 6 44 81 54 89
2940
0 0
0 0
...

output:

Unauthorized output

result:


Subtask #3:

score: 0
Wrong Answer

Test #13:

score: 16
Accepted
time: 0ms
memory: 3796kb

input:

2
0 1
60
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1

output:

0

result:

ok correct

Test #14:

score: -16
Wrong Answer
time: 0ms
memory: 3744kb

input:

5
0 4 1 3 2
150
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
...

output:

2
2 4
4 0

result:

wrong answer the final array is not sorted

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 1ms
memory: 3892kb

input:

1800
530 1775 466 953 230 1179 944 752 990 1316 275 1029 158 152 1673 1706 172 115 599 1661 131 699 1112 454 551 1059 291 495 28 67 773 480 839 462 1210 757 879 285 439 3 1429 820 26 1023 942 199 356 625 1705 1421 144 1529 716 7 1485 1027 1599 696 517 1353 456 1389 273 1363 1414 1177 718 41 777 1621...

output:

1794
688 490
490 1687
1687 1024
1024 421
421 287
287 1029
1029 764
764 1320
1320 1257
1257 877
877 801
801 1384
1384 1363
1363 63
63 1353
1353 59
59 93
93 1783
1783 1289
1289 1785
1785 1032
1032 904
904 270
270 908
908 1387
1387 1600
1600 556
556 641
641 440
440 821
821 1608
1608 132
132 399
399 546...

result:

wrong answer the final array is not sorted

Subtask #6:

score: 0
Skipped

Dependency #5:

0%