109252024-04-19 12:20:02k_balintSzimmetrikus sorozatcpp17Accepted 100/100177ms41092 KiB
#include <bits/stdc++.h>
using namespace std;
const int c=2e5+5;

int n;
int arr[c];
vector<int> adj[c];
vector<int> comp;
bool vis[c];
vector<pair<int,int>> ans;

void dfs(int v, int val){
    vis[v]=1;
    for(int x:adj[v]){
        if(!vis[x]){
            ans.push_back(make_pair(comp[x], val));
            dfs(x, val);
        }
    }
}

int f(int k){
    return lower_bound(comp.begin(),comp.end(),k)-comp.begin();
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin>>n;

    comp.push_back(0);
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        comp.push_back(arr[i]);
    }

    sort(comp.begin(), comp.end());
    comp.resize(unique(comp.begin(),comp.end())-comp.begin());

    for(int i=1;i<=n;i++){
        int a = n-i+1;
        if(arr[i]==arr[a]) continue;
        adj[f(arr[i])].push_back(f(arr[a]));
    }

    for(int i=1;i<comp.size();i++){
        if(!vis[i]) dfs(i,comp[i]);
    }

    cout << ans.size() << '\n';
    for(pair<int,int> x:ans){
        cout << x.first << ' ' << x.second << '\n';
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted6ms11328 KiB
2Accepted76ms19088 KiB
subtask29/9
3Accepted6ms11908 KiB
4Accepted7ms12232 KiB
5Accepted7ms12572 KiB
6Accepted7ms12784 KiB
7Accepted7ms12788 KiB
subtask314/14
8Accepted7ms12924 KiB
9Accepted7ms12936 KiB
10Accepted6ms13296 KiB
11Accepted7ms13292 KiB
12Accepted6ms13188 KiB
13Accepted7ms13468 KiB
subtask425/25
14Accepted6ms13544 KiB
15Accepted6ms13592 KiB
16Accepted8ms14080 KiB
17Accepted8ms13996 KiB
18Accepted8ms14104 KiB
19Accepted8ms13844 KiB
20Accepted8ms13840 KiB
21Accepted7ms13788 KiB
subtask522/22
22Accepted104ms25248 KiB
23Accepted115ms40912 KiB
24Accepted115ms40952 KiB
25Accepted108ms25480 KiB
26Accepted104ms25488 KiB
27Accepted119ms39328 KiB
28Accepted115ms39676 KiB
29Accepted104ms25664 KiB
30Accepted103ms25648 KiB
31Accepted119ms40904 KiB
32Accepted115ms41092 KiB
33Accepted105ms25712 KiB
34Accepted101ms25728 KiB
35Accepted111ms32616 KiB
36Accepted108ms36768 KiB
37Accepted97ms25704 KiB
subtask630/30
38Accepted7ms14584 KiB
39Accepted76ms22108 KiB
40Accepted6ms11908 KiB
41Accepted7ms12232 KiB
42Accepted7ms12572 KiB
43Accepted7ms12784 KiB
44Accepted7ms12788 KiB
45Accepted7ms12924 KiB
46Accepted7ms12936 KiB
47Accepted6ms13296 KiB
48Accepted7ms13292 KiB
49Accepted6ms13188 KiB
50Accepted7ms13468 KiB
51Accepted6ms13544 KiB
52Accepted6ms13592 KiB
53Accepted8ms14080 KiB
54Accepted8ms13996 KiB
55Accepted8ms14104 KiB
56Accepted8ms13844 KiB
57Accepted8ms13840 KiB
58Accepted7ms13788 KiB
59Accepted104ms25248 KiB
60Accepted115ms40912 KiB
61Accepted115ms40952 KiB
62Accepted108ms25480 KiB
63Accepted104ms25488 KiB
64Accepted119ms39328 KiB
65Accepted115ms39676 KiB
66Accepted104ms25664 KiB
67Accepted103ms25648 KiB
68Accepted119ms40904 KiB
69Accepted115ms41092 KiB
70Accepted105ms25712 KiB
71Accepted101ms25728 KiB
72Accepted111ms32616 KiB
73Accepted108ms36768 KiB
74Accepted97ms25704 KiB
75Accepted172ms28904 KiB
76Accepted137ms26924 KiB
77Accepted59ms19784 KiB
78Accepted137ms27000 KiB
79Accepted111ms22464 KiB
80Accepted52ms18104 KiB
81Accepted52ms18104 KiB
82Accepted52ms18108 KiB
83Accepted177ms28904 KiB
84Accepted64ms19868 KiB
85Accepted115ms22464 KiB
86Accepted57ms18108 KiB
87Accepted57ms18100 KiB
88Accepted57ms18216 KiB
89Accepted57ms18320 KiB