QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#473082#2789. SortingRafi228 1ms4108kbC++141.9kb2024-07-11 21:44:342024-07-11 21:44:35

Judging History

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

  • [2024-07-11 21:44:35]
  • 评测
  • 测评结果:8
  • 用时:1ms
  • 内存:4108kb
  • [2024-07-11 21:44:34]
  • 提交

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) 
	{
		swap(pos[S[X[i]]],pos[S[Y[i]]]);
		swap(S[X[i]],S[Y[i]]);
		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]]);
	}
	FOR(i,0,n-1) debug(S[i]);
	FOR(i,0,ans-1) debug(P[i],Q[i]);
	return ans;
}



详细

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 1ms
memory: 4108kb

input:

1
0
1
0 0

output:

0

result:

ok correct

Test #2:

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

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: 3744kb

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: 3748kb

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: 3796kb

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: 3744kb

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: 0ms
memory: 3776kb

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: 3740kb

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: 3832kb

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
Runtime Error

Test #13:

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

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: 0
Accepted
time: 0ms
memory: 3996kb

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 1

result:

ok correct

Test #15:

score: -16
Runtime Error

input:

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

output:

Unauthorized output

result:


Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Wrong Answer

Test #28:

score: 20
Accepted
time: 1ms
memory: 3888kb

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:

ok correct

Test #29:

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

input:

1950
1718 335 1071 714 1080 1828 1472 410 553 1269 297 401 1021 621 1763 528 205 1231 406 5 715 876 1474 1110 653 862 838 291 1092 549 955 1334 1044 300 1070 720 1877 484 1597 1948 1078 28 87 1193 505 1024 1259 63 852 960 633 1573 713 504 15 820 1852 752 1601 1168 471 1903 499 693 1209 1492 56 908 9...

output:

1944
1223 535
535 298
298 999
999 1538
1538 1342
1342 1088
1088 404
404 1646
1646 1896
1896 1167
1167 1152
1152 1084
1084 1214
1214 416
416 1333
1333 579
579 1769
1769 1783
1783 1316
1316 753
753 1262
1262 1329
1329 409
409 1824
1824 549
549 29
29 410
410 7
7 751
751 1581
1581 1885
1885 417
417 1724...

result:

ok correct

Test #30:

score: -20
Wrong Answer
time: 1ms
memory: 3888kb

input:

1853
452 1299 444 1527 510 1801 34 1178 1589 1782 342 1800 735 761 879 999 1122 1772 236 566 1459 1256 1149 1498 1827 1027 715 1377 6 306 1811 950 500 890 196 1825 1568 1157 943 1422 475 1237 1792 1796 1363 1217 889 968 1439 1116 322 795 1088 1358 1833 96 118 543 1337 207 876 1144 805 215 1433 903 1...

output:

1844
1354 552
552 676
676 1660
1660 1099
1099 728
728 1249
1249 1273
1273 798
798 1593
1593 1243
1243 938
938 1160
1160 227
227 1715
1715 1465
1465 1464
1464 684
684 1193
1193 1349
1349 391
391 272
272 1029
1029 1201
1201 213
213 33
33 320
320 1199
1199 343
343 443
443 817
817 527
527 40
40 1616
161...

result:

wrong answer the final array is not sorted

Subtask #6:

score: 0
Skipped

Dependency #5:

0%