Submission details
Task:Pair sort
Sender:aalto26dw_002
Submission time:2026-09-23 17:19:19 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.01 sdetails
#10ACCEPTED0.01 sdetails
#11ACCEPTED0.01 sdetails
#12ACCEPTED0.01 sdetails
#13ACCEPTED0.01 sdetails
#14ACCEPTED0.01 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:25:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i=1;i<arr.size();i+=2){
      |                  ~^~~~~~~~~~~

Code

#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> arr(2*n+1);
    unordered_map<int, vector<int>> m;
    for (int i=1;i<=2*n;i++){
        cin >> arr[i];
        m[arr[i]].push_back(i);
    }
    /*
    for (const auto& p: m){
        cout << p.first << ": ";
        for (const auto & i: p.second){
            cout << i << ' ';
        }
        cout <<'\n';
    }*/
    vector<vector<int>> swaps(0, vector<int>(2));
    for (int i=1;i<arr.size();i+=2){
        //cout << arr[i] << "\n"; 
        int pos;
        if (arr[i]==arr[i+1]){
            continue;
        }
        if (i%2!=0){
            int index2;
            if (i==m[arr[i]][0]){
                pos=m[arr[i]][1];
                index2=1;
            } else {
                pos=m[arr[i]][0];
                index2=0;
            }

            int index1;
            if (m[arr[i+1]][0]==i+1){
                index1=0;
            } else {
                index1=1;
            }
            //cout << pos << ' ' << index1 << ' ' << index2 << '\n';

            swap(m[arr[i+1]][index1], m[arr[pos]][index2]);            
            swap(arr[i+1], arr[pos]);
            swaps.push_back({i+1, pos});
            /*
            for (const auto& p: m){
                cout << p.first << ": ";
                for (const auto & i: p.second){
                    cout << i << ' ';
                }
                cout <<'\n';
            }
            for (const auto i: arr){
                cout << i << ' ';
            }
            cout << '\n';*/
        }
    }

    cout << swaps.size() << '\n';
    for (const auto& s: swaps){
        cout << s[0] << ' ' << s[1] << '\n';
    }
    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
5
3 2 4 5 1 3 2 1 4 5 

correct output
3
2 6
4 9
6 8

user output
3
2 6
4 9
6 8

Test 2

Verdict: ACCEPTED

input
5
3 2 4 5 1 3 2 1 4 5 

correct output
3
2 6
4 9
6 8

user output
3
2 6
4 9
6 8

Test 3

Verdict: ACCEPTED

input
10
3 6 6 8 8 9 9 1 4 5 2 4 10 2 1...

correct output
9
2 17
4 17
6 17
8 17
...

user output
9
2 17
4 17
6 17
8 17
...

Test 4

Verdict: ACCEPTED

input
10
3 6 6 8 8 9 9 1 4 5 2 4 10 2 1...

correct output
9
2 17
4 17
6 17
8 17
...

user output
9
2 17
4 17
6 17
8 17
...

Test 5

Verdict: ACCEPTED

input
50
47 26 6 35 13 18 9 19 14 50 34...

correct output
48
2 87
4 78
6 71
8 55
...

user output
48
2 87
4 78
6 71
8 55
...

Test 6

Verdict: ACCEPTED

input
50
47 26 6 35 13 18 9 19 14 50 34...

correct output
48
2 87
4 78
6 71
8 55
...

user output
48
2 87
4 78
6 71
8 55
...

Test 7

Verdict: ACCEPTED

input
100
56 26 6 35 60 72 9 55 83 51 58...

correct output
97
2 77
4 108
6 141
8 55
...

user output
97
2 77
4 108
6 141
8 55
...

Test 8

Verdict: ACCEPTED

input
100
56 26 6 35 60 72 9 55 83 51 58...

correct output
97
2 77
4 108
6 141
8 55
...

user output
97
2 77
4 108
6 141
8 55
...

Test 9

Verdict: ACCEPTED

input
500
56 146 351 35 281 235 354 449 ...

correct output
497
2 758
4 820
6 125
8 243
...

user output
497
2 758
4 820
6 125
8 243
...

Test 10

Verdict: ACCEPTED

input
500
56 146 351 35 281 235 354 449 ...

correct output
497
2 758
4 820
6 125
8 243
...

user output
497
2 758
4 820
6 125
8 243
...

Test 11

Verdict: ACCEPTED

input
1000
603 596 351 885 530 235 354 56...

correct output
993
2 256
4 1534
6 816
8 1057
...

user output
993
2 256
4 1534
6 816
8 1057
...

Test 12

Verdict: ACCEPTED

input
1000
603 596 351 885 530 235 354 56...

correct output
993
2 256
4 1534
6 816
8 1057
...

user output
993
2 256
4 1534
6 816
8 1057
...

Test 13

Verdict: ACCEPTED

input
5000
1594 596 1797 3776 1201 235 35...

correct output
4993
2 1548
4 9062
6 6397
8 8296
...

user output
4993
2 1548
4 9062
6 6397
8 8296
...

Test 14

Verdict: ACCEPTED

input
5000
1594 596 1797 3776 1201 235 35...

correct output
4993
2 1548
4 9062
6 6397
8 8296
...

user output
4993
2 1548
4 9062
6 6397
8 8296
...