CF987E 思维题 没有思路,经典不会就搜,坏习惯。 可以发现3n 和 7n+1奇偶性不同,就从这里下手。 思路: 假设最终的序列中逆序对数量为k. 每次交换都会使逆序对+1或者-1,假设+1数量为x,-1数量为y. 对于3n的操作。x + y = 3n, x - y = k. 所以2x = 3n + k. 所以3n 和 k同奇或同偶。 所以判断一下逆序对个数和3*n的奇偶性即可。
20级带lao写了O(n)的做法,与permutation性质有关,tql,我不会,只会树状数组。
// Problem: E. Petr and Permutations
// Contest: Codeforces - Codeforces Round #485 (Div. 2)
// URL: https://codeforces.com/problemset/problem/987/E
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define fir(i,a,b) for(int i=a;iT;
read(T);
while(T--)
{
solve();
}
return 0;
}
晚安。