CF 1093 G. Multidimensional Queries】的更多相关文章

G. Multidimensional Queries 链接 分析: 考虑如何去掉绝对值符号. $\sum \limits_{i = 1}^{k} |a_{x, i} - a_{y, i}|$,由于k比较小,考虑枚举每一维的符号,发现如果不是最终的答案,结果会变小,不影响取max的操作. 然后就是单点修改,区间查询最大最小值. 代码: #include<cstdio> #include<algorithm> #include<cstring> #include<i…
POJ2926 先学会这个哈夫曼距离的处理才能做 cf 的G #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #include <cmath> using namespace std; #define maxn 100005 const int inf = (int)1e9; ]; <<+],mx[<<+]; in…
[CF1093G]Multidimensional Queries 题目大意: \(k(k\le5)\)维空间中有\(n(n\le2\times10^5)\)个点.\(m\)次操作,操作包含一下两种: 将第\(i\)个点改为\((b_1,b_2,\ldots,b_k)\). 询问编号在\([l,r]\)内的所有点对中,曼哈顿距离的最大值. 思路: 枚举每一维坐标对答案的贡献的符号是正还是负,总共\(2^{k-1}\)种情况.每种情况用线段树维护最大/最小值.询问时在每棵线段树上查询区间最大值-区…
题目:http://codeforces.com/contest/1093/problem/G 只好看看题解:https://codeforces.com/blog/entry/63877 主要是把绝对值符号消掉,变成枚举正负.因为答案不会变差,所以不用管符号应该是什么,直接对应地取 max . min 即可. #include<cstdio> #include<cstring> #include<algorithm> #define ls Ls[cr] #define…
题目链接: https://codeforces.com/contest/1093/problem/G 题目: 题意: 在k维空间中有n个点,每次给你两种操作,一种是将某一个点的坐标改为另一个坐标,一种操作是查询[l,r]中曼哈顿距离最大的两个点的最大曼哈顿距离. 思路: 对于曼哈顿距离,我们将其绝对值去掉会发现如下规律(以二维为例): 故这题我们可以用线段树来维护[l,r]中上述每种情况的最大值和最小值,用二进制来枚举xy的符号(1为正,0为负),最后答案是 每种情况中区间最大值-区间最小值…
G. Distinctification 链接 分析: 线段树合并 + 并查集. 最后操作完后a连续递增的一段,b一定是递减的.最后的答案是$\sum (a_{new}-a_{odd}) \times b_i$,即改变后的a减去之前的a. 那么对于连续的一段考虑怎么求.按照bi建立权值线段树,线段树的一个节点的答案就是 左区间的答案+右区间的答案+左区间的和 × 右区间的个数. 即最大的$b_i$乘1,次大的乘2,...,最小的乘(n-1)分别是每个$b_i$的排名.这是对b排序后,新的答案,减…
G. Xor-matic Number of the Graph 链接 题意: 给定一个无向图,一个interesting的三元环(u,v,s)满足,从u到v的路径上的异或和等于s,三元环的权值为s,求所有三元环权值之和. 分析: 求出所有的三元环,建立线性基,然后逐位求每一位的贡献. 代码: #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include&…
Polycarp has n coins, the value of the i-th coin is ai. It is guaranteed that all the values are integer powers of 2 (i.e. ai=2d for some non-negative integer number d). Polycarp wants to know answers on q queries. The j-th query is described as inte…
题目:http://codeforces.com/contest/914/problem/G 其实就是把各种都用子集卷积和FWT卷起来算即可: 注意乘 Fibonacci 数组的位置: 子集卷积时不能一边做一边更新卷积的数组! 代码如下: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; int rd() { ,f=; cha…
http://codeforces.com/contest/369/problem/E 题意:输入n,m; n 代表有多少个线段,m代表有多少个询问点集.每一个询问输出这些点的集合所占的线段的个数. 思路:求出没有被点的覆盖的线段的个数,n-这个个数就是所求的. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 2000000 using namespace std; ; int…