每次交换:逆序对的数量+1或者-1;

假设最后逆序对数量为 sum;

①x+y=3n;

②x-y=sum;

-> 3n+sum为偶数;

所以 n 和 sum 必须奇偶一样;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 1000005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-4
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {ll x = 0;char c = getchar();bool f = false;while (!isdigit(c)) {if (c == '-') f = true;c = getchar();}while (isdigit(c)) {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f ? -x : x;
}ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; }/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {if (!b) {x = 1; y = 0; return a;}ans = exgcd(b, a%b, x, y);ll t = x; x = y; y = t - a / b * y;return ans;
}
*/int n;
int a[maxn];
int b[maxn];
int c[maxn];void add(int x) {while (x <= n) {c[x]++; x += x & -x;}
}
int query(int x) {int res = 0;while (x > 0) {res += c[x]; x -= x & -x;}return res;
}
int main() {//ios::sync_with_stdio(0);rdint(n);for (int i = 1; i <= n; i++) {rdint(a[i]); b[i] = a[i];}sort(b + 1, b + 1 + n);int ans = 0;for (int i = 1; i <= n; i++) {add(lower_bound(b + 1, b + 1 + n, a[i]) - b);ans += (i - query(lower_bound(b + 1, b + 1 + n, a[i] + 1) - b - 1));}if ((ans & 1) == (n & 1)) {cout << "Petr" << endl;}else cout << "Um_nik" << endl;return 0;
}

转载于:https://www.cnblogs.com/zxyqzy/p/10273657.html

CF986B Petr and Permutations 思维相关推荐

  1. Codeforces987 E. Petr and Permutations(思维+逆序对)

    题意: 一开始有一个长度为n的原排列a, 一次操作随机选择两个不同位置的数a(i)和a(j),然后交换. Petr会进行3n次操作,Alex会进行7n+1次操作. 现在给出结果序列,要求判断结果序列是 ...

  2. 【Codeforces 986B】Petr and Permutations

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] n为奇数时3n和7n+1奇偶性不同 n为偶数时也是如此 然后交换任意一对数 逆序对的对数的奇偶性会发生改变一次 求出逆序对 对n讨论得出答案. ...

  3. Codeforces 986B. Petr and Permutations(没想到这道2250分的题这么简单,早知道就先做了)

    这题真的只能靠直觉了,我没法给出详细证明. 解题思路: 1.交换3n次或者7n+1次,一定会出现一个为奇数,另一个为偶数. 2.用最朴素的方法,将n个数字归位,计算交换次数. 3.判断交换次数是否与3 ...

  4. CodeForces - 987E Petr and Permutations(树状数组+逆序对定理)

    题目链接:点击查看 题目大意:给出一个长度为 n 的序列,可能打乱过 3 * n 次,也可能打乱过 7 * n + 1 次,问到底打乱过多少次 题目分析:首先看出,3 * n 和 7 * n + 1 ...

  5. css绘制卡券优惠券_css3 绘制优惠券

    svm心得体会(2) 昨天和李老师讨论一会还是有所得的,虽然我发誓要早睡又泡汤了,又无原则晚睡了. 总结一下有这么几点心得认识: (1)MATLAB再带的svm工具箱得不到参数,必须在路径中添加lib ...

  6. Codeforces Round #485 (Div. 2)

    Codeforces986B [Petr and Permutations] 看到两个随机的swap次数,很容易想到跟奇偶性有关.然后就凉了.赛后思考了一下,这个思路应该没问题,那就需要考虑swap的 ...

  7. Codeforces Round #590 (Div. 3) E. Special Permutations 差分 + 思维

    传送门 文章目录 题意: 思路: 题意: 思路: 直接考虑比较难想,这种公式题基本都是将部分答案看成一个整体,考虑xi,xi+1x_i,x_{i+1}xi​,xi+1​的贡献的. 假设当前的xi=x, ...

  8. 排列组合思维导图_思维模型10 - Permutations and Combinations | 排列组合

    人生无时无刻不在做决策,有的决策可能只是决定晚上吃什么,而还有一些决策能够决定你后半生的到底能否幸福.我们小时候很多事情都是父母来帮助我们做决定,但是随着年龄的增长,越来越多的事情父母没办法帮我们下决 ...

  9. 算法工程师思维导图—数据结构与算法

    卖萌屋的妹子们(划掉)作者团整理的算法工程师思维导图,求职/自我提升/查漏补缺神器.该手册一共分为数据结构与算法.数学基础.统计机器学习和深度学习四个部分. 点击这里查看具体使用指南.该手册有两种获取 ...

最新文章

  1. php对象持久化,在 Oracle 中完成 PHP5 对象的持久
  2. 如何使用fdisk与parted对不同容量硬盘分区
  3. 计算机考研计组简答题复习-本篇长期更新
  4. Scala 语言输出的三种方式
  5. Maven依赖Scope标签用法
  6. 《弗洛伊德及其后继者》读书笔记(part1)--西格蒙德·弗洛伊德与经典精神分析传统
  7. Java基本流程控制语句
  8. linux内核参数的程序,技巧-Linux内核参数调整办法
  9. Spring Integration Java DSL示例–使用Jms名称空间工厂进一步简化
  10. 文档声明和HTML样式表
  11. 深入理解javascript
  12. [转]MIDI常识20条
  13. 连接显示器与计算机主机的接口电路是,液晶显示器VGA模拟输入接口电路
  14. python3 二进制文件比较_《Python 3程序开发指南(第2版•修订版)》——7.4 随机存取二进制文件...
  15. 蔡学镛:文档模板,天使或恶魔?
  16. linux usb有线网卡驱动_Linux系统安装R8169网卡驱动的方法
  17. 笔记本电脑+USB接口GPS+WM6模拟器+PPC版城际通
  18. TX-LCN分布式事务之TCC模式
  19. 树莓派pico从零开始的入门(一)
  20. 【计算机三级信息安全】访问控制模型

热门文章

  1. UDP对应的应用层协议之DHCP协议
  2. 电脑上同时安装了tensorflow和tensorflow-gpu,如何默认使用tensorflow-gpu
  3. TypeError: object.__init__() takes no parameters异常报错分析
  4. Ubuntu 必装软件及安装教程
  5. 5.8.1 创建类型实例
  6. racle的STRUCT和VARRAY的读写方法
  7. P2817 宋荣子的城堡
  8. JS模式--状态模式(状态机)
  9. 一个web项目在myeclipse中add deployment时无法被识别出来的原因
  10. redis源码笔记-adlist