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
|
using namespace std;
const int maxn = 2010;
int a[maxn], b[maxn], c[maxn]; int n; typedef pair<int, int> P; int ans; vector<P> res;
int (){ scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = 1; i <= n; i++) scanf("%d", &b[i]), c[b[i]] = i; for(int i = 1; i <= n; i++){ for(int j = i - 1, nowi = i; j >= c[a[nowi]]; j--){ if(c[a[j]] >= nowi){ ans += nowi - j; res.push_back(P{nowi, j}); swap(a[nowi], a[j]); nowi = j; } } } printf("%dn%dn", ans, res.size()); for(auto &it : res) printf("%d %dn", it.first, it.second); return 0; }
|
近期评论