187442025-11-03 21:35:00ercseferencSzimmetrikus sorozatcpp17Runtime error 48/100344ms131072 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct par{int a,b;};
struct adatszam{int ert,ind,csop;};
bool has1(adatszam m, adatszam n){
    return m.ert<n.ert;}
bool has2(adatszam m, adatszam n){
    return m.ind<n.ind;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); vector<par>b;
    int n,x,y; cin>>n;
    vector<adatszam>a(n);
    for(int i=0; i<n; i++){cin>>a[i].ert; a[i].ind=i;}
    vector<vector<int> >csoportok; int t=0;
    sort(a.begin(),a.end(), has1);
    vector<int>ures; csoportok.push_back(ures);
   for(int i=0; i<n-1; i++){
        csoportok[t].push_back(a[i].ind);
        a[i].csop=t;
        if(a[i].ert!=a[i+1].ert){
                t++;
                csoportok.push_back(ures);}}
    a[n-1].csop=t; csoportok[t].push_back(a[n-1].ind);
    sort(a.begin(),a.end(), has2);
    for(int i=0; i<n/2; i++){
        if(a[i].ert!=a[n-i-1].ert){
            if(a[i].ert>a[n-i-1].ert){
                x=n-i-1, y=i;}
            else {x=i; y=n-i-1;}
            par q; q.a=a[y].ert; q.b=a[x].ert; b.push_back(q);
            int v=csoportok[a[y].csop].size();
            int w=a[y].csop;
            int r=a[x].csop;
            int u=a[x].ert;
            if(w==r)break;
            for(int j=0; j<v; j++){
                csoportok[r].push_back(csoportok[w][j]);
                a[csoportok[w][j]].ert=u;
                a[csoportok[w][j]].csop=r;}
            csoportok[w].clear();}}
    cout<<b.size()<<endl;
    for(int i=0; i<b.size(); i++)cout<<b[i].a<<" "<<b[i].b<<endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted137ms10860 KiB
subtask29/9
3Accepted2ms316 KiB
4Accepted2ms316 KiB
5Accepted2ms316 KiB
6Accepted2ms508 KiB
7Accepted2ms564 KiB
subtask314/14
8Accepted1ms352 KiB
9Accepted1ms532 KiB
10Accepted1ms508 KiB
11Accepted1ms316 KiB
12Accepted1ms316 KiB
13Accepted1ms316 KiB
subtask425/25
14Accepted1ms316 KiB
15Accepted2ms316 KiB
16Accepted4ms492 KiB
17Accepted4ms688 KiB
18Accepted4ms564 KiB
19Accepted4ms564 KiB
20Accepted3ms564 KiB
21Accepted2ms576 KiB
subtask50/22
22Accepted210ms13236 KiB
23Runtime error289ms131072 KiB
24Accepted287ms16316 KiB
25Accepted216ms13244 KiB
26Accepted203ms13276 KiB
27Runtime error280ms131072 KiB
28Accepted268ms19572 KiB
29Accepted202ms13284 KiB
30Accepted194ms13284 KiB
31Runtime error277ms131072 KiB
32Accepted284ms23784 KiB
33Accepted221ms13216 KiB
34Accepted197ms13284 KiB
35Runtime error266ms131072 KiB
36Accepted282ms25824 KiB
37Accepted212ms13288 KiB
subtask60/30
38Accepted1ms316 KiB
39Accepted143ms10984 KiB
40Accepted2ms316 KiB
41Accepted2ms316 KiB
42Accepted2ms316 KiB
43Accepted2ms508 KiB
44Accepted2ms564 KiB
45Accepted1ms352 KiB
46Accepted1ms532 KiB
47Accepted1ms508 KiB
48Accepted1ms316 KiB
49Accepted1ms316 KiB
50Accepted1ms316 KiB
51Accepted1ms316 KiB
52Accepted2ms316 KiB
53Accepted4ms492 KiB
54Accepted4ms688 KiB
55Accepted4ms564 KiB
56Accepted4ms564 KiB
57Accepted3ms564 KiB
58Accepted2ms576 KiB
59Accepted210ms13236 KiB
60Runtime error289ms131072 KiB
61Accepted287ms16316 KiB
62Accepted216ms13244 KiB
63Accepted203ms13276 KiB
64Runtime error280ms131072 KiB
65Accepted268ms19572 KiB
66Accepted202ms13284 KiB
67Accepted194ms13284 KiB
68Runtime error277ms131072 KiB
69Accepted284ms23784 KiB
70Accepted221ms13216 KiB
71Accepted197ms13284 KiB
72Runtime error266ms131072 KiB
73Accepted282ms25824 KiB
74Accepted212ms13288 KiB
75Accepted305ms19388 KiB
76Accepted210ms17088 KiB
77Accepted112ms8568 KiB
78Accepted231ms20660 KiB
79Accepted162ms20704 KiB
80Accepted120ms10228 KiB
81Accepted122ms10212 KiB
82Accepted119ms10428 KiB
83Accepted344ms20236 KiB
84Accepted115ms8616 KiB
85Accepted174ms20668 KiB
86Accepted125ms10432 KiB
87Accepted127ms10424 KiB
88Accepted128ms10440 KiB
89Accepted123ms10424 KiB