Max Mex 题目地址:https://codeforces.com/contest/1084/problem/F 然后合并时注意分情况讨论: 参考代码: #include<bits/stdc++.h> using namespace std; #define pb push_back #define mkp make_pair #define fi first #define se second typedef long long ll; typedef pair<int,int&g…
C. Max Mex https://codeforces.com/contest/1083/problem/C 题意: 一棵$n$个点的树,每个点上有一个数(每个点的上的数互不相同,而且构成一个0~n-1的排列),要求找到一条路径,使得路径的$mex$最大. 分析: 问题转化为,查询一个a,0~a-1是否可以都存在于一条路径上.类似线段树维护连通性,这里线段树的每个点表示所对应的区间[l,r]是否可以存在于一条路径上.合并的时候用lca和dfs序的位置判断.然后就是线段树上二分了. 代码: #…
Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和,用于之后快速求和.将原数组排序后去重,枚举每一个数做lead的情况下,其余数减少后再求和的结果.不断维护最大值即可. PS:这里用到了一个方便的函数unique()来去重,使用前需要先将数组排序,参数为数组的首地址和尾后地址,返回新的尾后地址.(该函数没有将重复的元素删除,只是放到了尾地址后面)可…
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is…
F - Expected Square Beauty 思路:https://codeforces.com/blog/entry/68111 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define y1 y11 #define fi first #define se second #define…
F - Ivan and Burgers 思路:线性基+贪心,保存线性基中每一位的最后一个 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#d…
F. Teodor is not a liar! time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;m] segm…
http://codeforces.com/problemset/problem/797/F F. Mice and Holes time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output One day Masha came home and noticed n mice in the corri…
Discription It's the turn of the year, so Bash wants to send presents to his friends. There are n cities in the Himalayan region and they are connected by m bidirectional roads. Bash is living in city s. Bash has exactly one friend in each of the oth…
题目链接:http://codeforces.com/contest/618/problem/F 题目: 题目大意: 有两个大小为 N 的可重集 A, B, 每个元素都在 1 到 N 之间. 分别找出 A 和 B 的一个子集, 使得这两个子集元素之和相等. 分别输出集合A和集合B的子集的个数以及子集中元素在原集合中的位置 N ≤ $10^6$ 题解: 首先我们证明一个结论,存在一组方案,满足两个子集在A中和在B中都是连续的一段 把两个集合看成两个数组,分别计算出前缀和sa,sb 对于每个i(0<…