107092024-04-10 09:44:25szilSzimmetrikus sorozatcpp17Accepted 100/100145ms37584 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAXN = 200'001;

int a[MAXN], mine;
bool vis[MAXN];
vector<int> c;
vector<int> g[MAXN];
vector<pair<int, int>> ans;

void dfs(int u) {
    vis[u] = true;
    mine = min(mine, u);
    c.emplace_back(u);
    for (int v : g[u]) {
        if (!vis[v]) {
            dfs(v);
        }
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<int> comp;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        comp.emplace_back(a[i]);
    }
    sort(comp.begin(), comp.end());
    comp.erase(unique(comp.begin(), comp.end()), comp.end());
    for (int i = 1; i <= n; i++) a[i] = lower_bound(comp.begin(), comp.end(), a[i])-comp.begin();
    for (int i = 1; i <= n; i++) {
        if (a[i] != a[n-i+1]) {
            g[a[i]].emplace_back(a[n-i+1]);
        }
    }

    for (int i = 0; i < comp.size(); i++) {
        if (!vis[i]) {
            mine = 1e9;
            dfs(i);
            for (int j : c) {
                if (j != mine) {
                    ans.emplace_back(comp[j], comp[mine]);
                }
            }
            c.clear();
        }
    }

    cout << ans.size() << "\n";
    for (auto [a, b] : ans) cout << a << " " << b << "\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted6ms11260 KiB
2Accepted64ms19156 KiB
subtask29/9
3Accepted7ms11840 KiB
4Accepted7ms12172 KiB
5Accepted7ms12248 KiB
6Accepted7ms12596 KiB
7Accepted7ms12560 KiB
subtask314/14
8Accepted7ms12400 KiB
9Accepted7ms12400 KiB
10Accepted7ms12656 KiB
11Accepted6ms12876 KiB
12Accepted7ms12824 KiB
13Accepted7ms13080 KiB
subtask425/25
14Accepted6ms13176 KiB
15Accepted7ms13456 KiB
16Accepted8ms13584 KiB
17Accepted8ms13788 KiB
18Accepted8ms13756 KiB
19Accepted8ms13740 KiB
20Accepted7ms14000 KiB
21Accepted7ms14164 KiB
subtask522/22
22Accepted90ms25352 KiB
23Accepted107ms37584 KiB
24Accepted104ms37476 KiB
25Accepted93ms25460 KiB
26Accepted90ms25436 KiB
27Accepted105ms36436 KiB
28Accepted107ms36440 KiB
29Accepted92ms25444 KiB
30Accepted89ms25436 KiB
31Accepted104ms37028 KiB
32Accepted101ms37020 KiB
33Accepted90ms25432 KiB
34Accepted86ms25452 KiB
35Accepted100ms31368 KiB
36Accepted103ms34604 KiB
37Accepted90ms25640 KiB
subtask630/30
38Accepted6ms14264 KiB
39Accepted64ms22152 KiB
40Accepted7ms11840 KiB
41Accepted7ms12172 KiB
42Accepted7ms12248 KiB
43Accepted7ms12596 KiB
44Accepted7ms12560 KiB
45Accepted7ms12400 KiB
46Accepted7ms12400 KiB
47Accepted7ms12656 KiB
48Accepted6ms12876 KiB
49Accepted7ms12824 KiB
50Accepted7ms13080 KiB
51Accepted6ms13176 KiB
52Accepted7ms13456 KiB
53Accepted8ms13584 KiB
54Accepted8ms13788 KiB
55Accepted8ms13756 KiB
56Accepted8ms13740 KiB
57Accepted7ms14000 KiB
58Accepted7ms14164 KiB
59Accepted90ms25352 KiB
60Accepted107ms37584 KiB
61Accepted104ms37476 KiB
62Accepted93ms25460 KiB
63Accepted90ms25436 KiB
64Accepted105ms36436 KiB
65Accepted107ms36440 KiB
66Accepted92ms25444 KiB
67Accepted89ms25436 KiB
68Accepted104ms37028 KiB
69Accepted101ms37020 KiB
70Accepted90ms25432 KiB
71Accepted86ms25452 KiB
72Accepted100ms31368 KiB
73Accepted103ms34604 KiB
74Accepted90ms25640 KiB
75Accepted136ms28840 KiB
76Accepted111ms25900 KiB
77Accepted52ms19768 KiB
78Accepted112ms25924 KiB
79Accepted86ms22224 KiB
80Accepted82ms18036 KiB
81Accepted82ms18044 KiB
82Accepted82ms18044 KiB
83Accepted145ms28840 KiB
84Accepted59ms19784 KiB
85Accepted90ms22232 KiB
86Accepted90ms18044 KiB
87Accepted90ms18048 KiB
88Accepted90ms18036 KiB
89Accepted87ms18044 KiB