#ifdef _MSC_VER
#ifndef __GNUC__
#pragma warning(disable: 4996)
#endif
#define main main0
#endif
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
vector<int> wzrosty;
bool sortuj(int lhs, int rhs) {
return wzrosty[lhs] < wzrosty[rhs];
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int n;
wzrosty.clear();
vector<int> kolejnosc;
kolejnosc.clear();
vector<vector<int>> rundy;
rundy.clear();
cin >> n;
wzrosty.resize(n+1);
kolejnosc.resize(n+1);
for(int i = 1; i <= n; ++i) {
cin >> wzrosty[i];
kolejnosc[i] = i;
}
sort(kolejnosc.begin() + 1, kolejnosc.end(), sortuj);
for(int i = 1; i <= n; ++i) {
if(kolejnosc[i] == i || kolejnosc[i] == 0)
continue;
size_t r = 0;
for(int j = i, k; kolejnosc[j] != 0; j = k) {
if(rundy.size() <= r)
rundy.resize(r+1);
rundy[r++].push_back(j);
k = kolejnosc[j];
kolejnosc[j] = 0;
}
}
if(rundy.size() < 2) {
cout << "0\n";
return 0;
}
size_t runda = rundy[0].size() - 1;
cout << rundy.size() - 1 << '\n';
for(size_t i = 1; i < rundy.size(); ++i) {
cout << (runda + 1) * 2 << '\n';
for(size_t j = 0; j <= runda; ++j)
cout << rundy[0][j] << ' ';
for(int j = runda; j >= 0; --j)
cout << rundy[i][j] << ' ';
cout << '\n';
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #ifdef _MSC_VER #ifndef __GNUC__ #pragma warning(disable: 4996) #endif #define main main0 #endif #include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; vector<int> wzrosty; bool sortuj(int lhs, int rhs) { return wzrosty[lhs] < wzrosty[rhs]; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; wzrosty.clear(); vector<int> kolejnosc; kolejnosc.clear(); vector<vector<int>> rundy; rundy.clear(); cin >> n; wzrosty.resize(n+1); kolejnosc.resize(n+1); for(int i = 1; i <= n; ++i) { cin >> wzrosty[i]; kolejnosc[i] = i; } sort(kolejnosc.begin() + 1, kolejnosc.end(), sortuj); for(int i = 1; i <= n; ++i) { if(kolejnosc[i] == i || kolejnosc[i] == 0) continue; size_t r = 0; for(int j = i, k; kolejnosc[j] != 0; j = k) { if(rundy.size() <= r) rundy.resize(r+1); rundy[r++].push_back(j); k = kolejnosc[j]; kolejnosc[j] = 0; } } if(rundy.size() < 2) { cout << "0\n"; return 0; } size_t runda = rundy[0].size() - 1; cout << rundy.size() - 1 << '\n'; for(size_t i = 1; i < rundy.size(); ++i) { cout << (runda + 1) * 2 << '\n'; for(size_t j = 0; j <= runda; ++j) cout << rundy[0][j] << ' '; for(int j = runda; j >= 0; --j) cout << rundy[i][j] << ' '; cout << '\n'; } return 0; } |
English