题意:
给出一个长度为n的序列,求出是谁操作的(原序列为从小到大的序列),Peter的操作次数为3n,Alex的操作次数为7n+1
解析:
我们来看这个序列中的逆序对,逆序对的个数为偶数则操作次数为偶数,逆序对的个数为奇数,则操作次数为奇数
然后树状数组求逆序对即可
#include <bits/stdc++.h> #define mem(a, b) memset(a, b, sizeof(a)) using namespace std; const int maxn = 1e6+10, INF = 0x7fffffff; int c[maxn]; int n; int lowbit(int x) { return x & (-x); } void add(int x, int y) { for(int i=x; i<=n; i+=lowbit(i)) c[i] += y; } int get_sum(int x) { int res = 0; for(int i=x; i>0; i-=lowbit(i)) res += c[i]; return res; } int main() { int x; int res = 0; cin>> n; for(int i=0; i<n; i++) { cin>> x; int ans = get_sum(x); res += i - ans; add(x, 1); } int a = 3 * n, b = 7 * n + 1; if(res & 1) { if(a & 1) cout<< "Petr" <<endl; else cout<< "Um_nik" <<endl; } else { if(a & 1) cout<< "Um_nik" <<endl; else cout<< "Petr" <<endl; } return 0; }