Codeforces Round #563 (Div. 2)/CF1174

CF1174A Ehab Fails to Be Thanos

其实就是要\(\sum\limits_{i=1}^n a_i\)与\(\sum\limits_{n+1}^{2n}a_i\)差值最大,排一下序就好了

CF1174B Ehab Is an Odd Person

一个显然的结论就是如果至少有一个奇数和一个偶数,那么是可以随意调整的,也就是升序排序

否则不可以进行任何操作

code

CF1174C Ehab and a Special Coloring Problem

与\(x\)互质的数填不同的数,把有向关系表示出来,发现边数是不能承受的

反过来想,成倍数关系填相同的数,把这些数想象成一条链,而这条链开始的数一定是质数,\(\sum\limits_{prime_i}\frac{n}{prime_i}\)是可以承受的

把这条链的点赋一个相同的值

code

CF1174D Ehab and the Expected XOR Problem

求出答案序列的异或前缀和\(sum_i\),\([l,r]\)子段异或和可表示为\(sum_r\bigoplus sum_{l-1}\)

故转换问题为,填\(sum\)数组,数组内的元素不为\(0\)且互不相同,且两两异或不为\(x\)

预处理\(x\)为多对值,每对值异或起来为\(x\),显然是两两互不影响的,每对值选择任意一个填就行了

最后还得从\(sum_i=\bigoplus_{j=1}^i a_i\)转换为\(a_i\)

code

CF1174E Ehab and the Expected GCD Problem

先来填第一个数,为了保证\(f(p)\)最大,第一个数分解一下为\(\prod\limits_{p_i}p_i^{k_i}\)使得\(\sum\limits_{k_i}\)最大

显然第一个数为\(2^x3^y\)且\(y≤1\),否则可以把\(3^2\)换成\(2^3\),故第一个数最多有两种选择

定义函数\(Cout(x,y)=\frac{n}{2^x3^y}\)为n以内含因子\(2^x3^y\)的个数

设\(f_{i,x,y}\)为填到第\(i\)个数后\(gcd_{j=1}^i a_i=2^x3^y\)的方案数,显然最后的答案为\(f_{n,0,0}\)

code

CF1174F Ehab and the Big Finale

\(x\)为隐藏节点,\(dep_x=d(1,x)\)
\((1)\):\(u=1\)

\((2)\):重链剖分,比如\(v\)为\(u\)的重链底部,查询\(dis(x,v)\)的长度,\(y=lca(v,x)\)且在重链上,\(dis(x,v)=dep_v+dep_x-2*dep_y,dep_y=(dep_v+dep_x-dis(x,v))/2\),则我们可以找到\(y\)

\((3)\):但\(dep_y=dep_x\)时,\(y\)为答案,退出

\((4)\):找到\(y\)后,查询\(sec=(y,x)\)上的第二个节点,\(u=sec\)返回\((2)\)

code

Codeforces Round #563 (Div. 2)/CF1174的更多相关文章

  1. Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem

    链接:https://codeforces.com/contest/1174/problem/C 题意: You're given an integer nn. For every integer i ...

  2. Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person

    链接:https://codeforces.com/contest/1174/problem/B 题意: You're given an array aa of length nn. You can ...

  3. Codeforces Round #563 (Div. 2) A. Ehab Fails to Be Thanos

    链接:https://codeforces.com/contest/1174/problem/A 题意: You're given an array aa of length 2n2n. Is it ...

  4. Codeforces Round #563 (Div. 2)C

    C. Ehab and a Special Coloring Problem 题目链接:http://codeforces.com/contest/1174/problem/C 题目 You're g ...

  5. Codeforces Round #563 (Div. 2)B

    B.Ehab Is an Odd Person 题目链接:http://codeforces.com/contest/1174/problem/B 题目 You’re given an array a ...

  6. Codeforces Round #563 (Div. 2)A

    A. Ehab Fails to Be Thanos 题目链接:http://codeforces.com/contest/1174/problem/A 题目 You’re given an arra ...

  7. Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem

    https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...

  8. Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale

    后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...

  9. Codeforces Round 563 (Div. 2) 题解

    自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则 ...

随机推荐

  1. 洛谷 P1217 回文质数

    洛谷 P1217 回文质数 链接 https://www.luogu.org/problem/P1217 题目 题目描述 因为 151 既是一个质数又是一个回文数(从左到右和从右到左是看一样的),所以 ...

  2. 编写Postgres扩展之三:调试

    原文:http://big-elephants.com/2015-10/writing-postgres-extensions-part-iii/ 编译:Tacey Wong 在上一篇关于编写Post ...

  3. HibernateTemplate的queryForList(sql)用法

    转自:https://blog.csdn.net/huanghaijin/article/details/7763580 List<User> list  = jdbcTemplate.q ...

  4. S3C2440 OpenJtag

    C:\Users\Administrator\Desktop>oflash.exe leds.bin +--------------------------------------------- ...

  5. stm32 视频小车

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 ...

  6. CentOS7.X基于LAMP环境搭建cacti

    1.搭建好LAMP环境 2.登录数据库创建cacti create database cacti default character set utf8; 创建cacti的账户密码 grant all ...

  7. ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

    pip install imagededup 时,报错:Cannot uninstall 'wrapt'. It is a distutils installed project and thus w ...

  8. windows RabbitMQ Server 环境配置中的一些坑

    原文:https://blog.csdn.net/lindonglian/article/details/55805637 RabbitMQ的服务端基于Erlang语言编写,要在机器上安装Rabbit ...

  9. python小知识点汇总

    一 写mysql 场景:自动化用例中需要构造数据,写入redis 表中已有该primary_key的记录,在现有基础上更新字段 表中无该记录,需要插入 # 请求传入table字段,db.table,c ...

  10. mybatis3.0-[topic10-14] -全局配置文件_plugins插件简介/ typeHandlers_类型处理器简介 /enviroments_运行环境 /多数据库支持/mappers_sql映射注册

    mybatis3.0-全局配置文件_   下面为中文官网解释 全局配置文件的标签需要按如下定义的顺序: <!ELEMENT configuration (properties?, setting ...