Skip to content

Instantly share code, notes, and snippets.

@krofna
Last active October 20, 2016 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krofna/a5b21e79ae907e046921693b8f54fd1f to your computer and use it in GitHub Desktop.
Save krofna/a5b21e79ae907e046921693b8f54fd1f to your computer and use it in GitHub Desktop.
#include <iostream>
#include <algorithm>
#include <list>
using namespace std;
typedef list<int>::iterator LI;
int find_derp(LI beg, int k, LI& out)
{
int ctr = 0;
while (*beg != k)
{
++beg;
++ctr;
}
out = beg;
return ctr;
}
void DoCase()
{
list<pair<int, int> > RJ;
int N;
cin >> N;
list<int> L;
for (int i = 0; i < N; ++i)
{
int l;
cin >> l;
L.push_back(l);
}
for (int i = 0; i < N; ++i)
{
int beg = 0;
LI itr;
int curr = find_derp(L.begin(), N - i, itr);
while (curr + 1 != N - i)
{
if (((beg + N - i) % 2) && curr == beg)
{
swap(*next(curr), curr);
LI.push_back(make_pair(beg, beg + 1));
++beg; ++curr;
}
int mid = (beg + N - i) / 2;
if (curr < mid)
{
LI.push_back(make_pair(begin, N - i - 1));
splice(next(L.begin()))
}
else
beg = mid;
}
}
cout << RJ.size() << '\n';
for (auto i = RJ.begin(); i != RJ.end(); ++i)
cout << i->begin + 1 << ' ' << i->end + 1 << '\n';
}
int main()
{
int T;
cin >> T;
while (T--)
DoCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment