codeforces Toy Sum】的更多相关文章

题意:给你x个集合的数,然后根据求y集合的数. 思路:根据对称性,先找出对称出现的个数cnt,然后对称位置的中如果出现一个的把另一个加入到y集合中,再找出cnt个对应位置都不出现的加入到y集合中. #include <cstdio> #include <cstring> #include <set> #include <algorithm> #define ll long long #define maxn 5000100 using namespace s…
题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris. There are exactly…
D. Toy Sum   time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a t…
题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 = 3的元素累加求和. 解题思路:线段树单点更新,每一个点维护5个值.分别表示从该段区间中i % 5 = t的和.然后两端区间合并时仅仅须要依据左孩子中元素的个数合并.所以有一个c表示区间上元素的个数. 由于有同样的数.所以要离线操做,将全部的数映射成位置,可是对于del则不须要映射,由于集合中肯定…
 传送门 Description Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris. There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chr…
题目链接:http://codeforces.com/problemset/problem/405/D 题目意思:从 1 - 1000000 中选择 n 个数:x1,x2,...,xn,对 x1-1,x2-1,...xn-1 求和得s1.然后在 1 - 1000000 中除已经选择过的n个数中选择一些数,假设为y1, y2,...ym,设s = 1000000,对s-y1,s-y2,...,s-ym求和,如果这个和与s1相等,则输出y1,y2,...,ym 可以这样想,由于集合X中:x1,x2,…
http://codeforces.com/problemset/problem/405/D 题意:已知集合S={1,2,3......1000000},s=1000000,从集合S中选择n个数,X={x1,x2,x3,...xn},计算sum=x1-1+x2-1+....+xn-1;从剩下的元素Y={y1,y2,y3,...}中选择一些数,使得s-y1+s-y2+...=sum,输出yi的个数及yi. 思路:可以根据元素的对称性来找yi.因为x-1=s-y,则y=s-x+1,即对于每一个x,对…
Codeforces 题面传送门 & 洛谷题面传送门 智商掉线/ll 本来以为是个奇怪的反悔贪心,然后便一直往反悔贪心的方向想就没想出来,看了题解才发现是个 nb 结论题. Conclusion. 在最优方案中,至多只有一个数组只有部分被选,其余数组要么全选要么全都不选. 证明:考虑调整.假设存在两个数组 \(x,y\) 分别选了前 \(p,q\) 个元素,这里不妨假设 \(a_{x,p+1}\ge a_{y,q+1}\),那么考虑从 \(y\) 数组中拎 \(l=\min(len_x-p,q)…
Codeforces 题面传送门 & 洛谷题面传送门 个人感觉这题称不上毒瘤. 首先看到选一条路径之类的字眼可以轻松想到点分治,也就是我们每次取原树的重心 \(r\) 并将路径分为经过重心和不经过重心两类路径.对于第二类路径我们肯定可以在对 \(r\) 所有子树进一步分治的过程中将其变成第一类路径,因此我们只用考虑怎样计算第一类路径的贡献即可. 显然对于一条第一类路径 \(x\to y\),我们要将其拆成 \(x\to r\) 和 \(r\to y\) 两部分分别处理,考虑怎样合并这两部分的贡献…
E. Sum of Remainders time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you shoul…