QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#659032#2789. SortingPioneer#0 0ms4016kbC++201.2kb2024-10-19 18:18:472024-10-19 18:18:47

Judging History

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

  • [2024-10-19 18:18:47]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:4016kb
  • [2024-10-19 18:18:47]
  • 提交

answer

#include "sorting.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX=200000;

int n,m;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	n=N,m=M;
    vector<int> v(n),need(n),rev(n);
	vector<pair<int,int>> swaps;
	for(int i=0;i<n;i++)v[i]=S[i],need[i]=i;
	vector<int> tov=need;
	for(int j=0;j<m;j++){
		swap(tov[X[j]],tov[Y[j]]);
	}
	vector<int> tov1(n);
	for(int i=0;i<n;i++)tov1[tov[i]]=i;
	swap(tov,tov1);
	for(int i=0;i<n;i++){
		tov1[tov[i]]=i;
	}
	rev=tov1;
	set<int> st;
	for(int i=0;i<n;i++){
		if(tov[i]!=v[i])st.insert(i);
	}
	for(int i=0;i<m;i++){
		swap(v[X[i]],v[Y[i]]);
		swap(tov1[tov[X[i]]],tov1[tov[Y[i]]]);
		swap(tov[X[i]],tov[Y[i]]);
		while(!st.empty()&&tov[*st.begin()]==v[*st.begin()])st.erase(st.begin());
		if(!st.empty()){
			int k=*st.begin();
			st.erase(st.begin());
			int j=tov1[v[k]];
			swaps.push_back({k,j});
			// cout<<k<<" "<<j<<" "<<v[k]<<" "<<tov[j]<<"\n";
			swap(v[k],v[j]);
		}
		else swaps.push_back({0,0});
	}
	// for(int x:v)cout<<x<<" ";
	// cout<<"\n";
	assert(v==need);
	for(int i=0;i<m;i++){
		P[i]=swaps[i].first;
		Q[i]=swaps[i].second;
	}
	return M;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

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

input:

1
0
1
0 0

output:

1
0 0

result:

ok correct

Test #2:

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

input:

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

output:

4
0 0
0 0
0 0
0 0

result:

ok correct

Test #3:

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

input:

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

output:

4
0 1
0 0
0 0
0 0

result:

ok correct

Test #4:

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

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:

9
0 1
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

result:

ok correct

Test #5:

score: 0
Runtime Error

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:

Unauthorized output

result:


Subtask #2:

score: 0
Runtime Error

Test #8:

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

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:

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

result:

ok correct

Test #9:

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

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:

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

result:

ok correct

Test #10:

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

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:

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

result:

ok correct

Test #14:

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

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:

150
2 0
4 2
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
...

result:

ok correct

Test #15:

score: 0
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
Runtime Error

Test #28:

score: 0
Runtime Error

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:

Unauthorized output

result:


Subtask #6:

score: 0
Skipped

Dependency #5:

0%