G. Multidimensional Queries

链接

分析:

  考虑如何去掉绝对值符号。

  $\sum \limits_{i = 1}^{k} |a_{x, i} - a_{y, i}|$,由于k比较小,考虑枚举每一维的符号,发现如果不是最终的答案,结果会变小,不影响取max的操作。

  然后就是单点修改,区间查询最大最小值。

代码:

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
#define Root 1, n, 1
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
struct Node{ int x[]; }A[N];
struct Que{ int opt, x[], l, r; }Q[N];
int ans[N]; struct SegmentTree{
int mx[N << ], mn[N << ];
void update(int l,int r,int rt,int p,int x) {
if (l == r) { mn[rt] = mx[rt] = x; return; }
int mid = (l + r) >> ;
if (p <= mid) update(lson, p, x);
else update(rson, p, x);
mx[rt] = max(mx[rt << ], mx[rt << | ]);
mn[rt] = min(mn[rt << ], mn[rt << | ]);
}
int query_min(int l,int r,int rt,int L,int R) {
if (L <= l && r <= R) return mn[rt];
int mid = (l + r) >> ;
if (R <= mid) return query_min(lson, L, R);
else if (L > mid) return query_min(rson, L, R);
else return min(query_min(lson, L, R), query_min(rson, L, R));
}
int query_max(int l,int r,int rt,int L,int R) {
if (L <= l && r <= R) return mx[rt];
int mid = (l + r) >> ;
if (R <= mid) return query_max(lson, L, R);
else if (L > mid) return query_max(rson, L, R);
else return max(query_max(lson, L, R), query_max(rson, L, R));
}
}T; int main() {
int n = read(), k = read();
for (int i = ; i <= n; ++i)
for (int j = ; j < k; ++j) A[i].x[j] = read();
int m = read();
for (int i = ; i <= m; ++i) {
Q[i].opt = read(); Q[i].r = -;
if (Q[i].opt == ) {
Q[i].l = read();
for (int j = ; j < k; ++j) Q[i].x[j] = read();
}
else {
Q[i].l = read(), Q[i].r = read();
}
}
int S = ( << k) - , now;
for (int s = ; s <= S; ++s) {
for (int i = ; i <= n; ++i) {
now = ;
for (int j = ; j < k; ++j) now += ((s >> j) & ) ? (A[i].x[j]) : (-A[i].x[j]);
T.update(Root, i, now);
}
for (int i = ; i <= m; ++i) {
if (Q[i].opt == ) {
int mn = T.query_min(Root, Q[i].l, Q[i].r);
int mx = T.query_max(Root, Q[i].l, Q[i].r);
ans[i] = max(ans[i], mx - mn);
}
else {
now = ;
for (int j = ; j < k; ++j) now += ((s >> j) & ) ? (Q[i].x[j]) : (-Q[i].x[j]);
T.update(Root, Q[i].l, now);
}
}
}
for (int i = ; i <= m; ++i) {
if (Q[i].r == -) continue;
printf("%d\n", ans[i]);
}
return ;
}

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

  1. POJ-2926-Requirements&&Educational Codeforces Round 56G. Multidimensional Queries 【哈夫曼距离】

    POJ2926 先学会这个哈夫曼距离的处理才能做 cf 的G #include <iostream> #include <stdio.h> #include <algor ...

  2. [CF1093G]Multidimensional Queries

    [CF1093G]Multidimensional Queries 题目大意: \(k(k\le5)\)维空间中有\(n(n\le2\times10^5)\)个点.\(m\)次操作,操作包含一下两种: ...

  3. CF 1093G Multidimensional Queries——线段树(消去绝对值符号)

    题目:http://codeforces.com/contest/1093/problem/G 只好看看题解:https://codeforces.com/blog/entry/63877 主要是把绝 ...

  4. Multidimensional Queries(二进制枚举+线段树+Educational Codeforces Round 56 (Rated for Div. 2))

    题目链接: https://codeforces.com/contest/1093/problem/G 题目: 题意: 在k维空间中有n个点,每次给你两种操作,一种是将某一个点的坐标改为另一个坐标,一 ...

  5. CF 1051 G. Distinctification

    G. Distinctification 链接 分析: 线段树合并 + 并查集. 最后操作完后a连续递增的一段,b一定是递减的.最后的答案是$\sum (a_{new}-a_{odd}) \times ...

  6. CF 724 G. Xor-matic Number of the Graph

    G. Xor-matic Number of the Graph 链接 题意: 给定一个无向图,一个interesting的三元环(u,v,s)满足,从u到v的路径上的异或和等于s,三元环的权值为s, ...

  7. CF 1003D Coins and Queries【位运算/硬币值都为2的幂/贪心】

    Polycarp has n coins, the value of the i-th coin is ai. It is guaranteed that all the values are int ...

  8. CF 914 G Sum the Fibonacci —— 子集卷积,FWT

    题目:http://codeforces.com/contest/914/problem/G 其实就是把各种都用子集卷积和FWT卷起来算即可: 注意乘 Fibonacci 数组的位置: 子集卷积时不能 ...

  9. cf E. Valera and Queries

    http://codeforces.com/contest/369/problem/E 题意:输入n,m; n 代表有多少个线段,m代表有多少个询问点集.每一个询问输出这些点的集合所占的线段的个数. ...

随机推荐

  1. 写markdown用于Github上readme.md文件

    Markdown 文档地址 http://pan.baidu.com/s/1o6nu9To Markdown还有一系列衍生版本,用于扩展Markdown的功能(如表格.脚注.内嵌HTML等等),这些功 ...

  2. [UI] 精美UI界面欣赏[1]

    精美UI界面欣赏[1]

  3. C++项目规范

    https://segmentfault.com/a/1190000007659754

  4. Web通信协议:OSI、TCP、UDP、Socket、HTTP、HTTPS、TLS、SSL、WebSocket、Stomp

    1      各层的位置 1.1      OSI七层模型全景图 OSI是Open System Interconnect的缩写,意为开放式系统互联. 1.2      五层网络协议 在七层的基础上, ...

  5. 16:42 python历史

    python的作者是Guido van Rossum,大牛,2.7版本好像到2020年就不能用了,估计很多公司对此有很多的需求吧.

  6. multi_index_container

    转自:https://blog.csdn.net/buptman1/article/details/38657807 multi_index_container: Boost Multi-index ...

  7. Mysql 漏洞利用(越权读取文件,实战怎么从低权限拿到root密码)[转]

    cnrstar (Be My Personal Best!) | 2014-05-20 21:58 众所周知,Mysql的用户在没有File权限情况下是无法通过Load_file读文件或者通过into ...

  8. .NET Core 控制台项目中的Nuget打包类库及引用

    由于使用的是MAC版本的VSCode,所以全部是通过dotnet命令来完成的. 1.dotnet new lib 创建类库项目: 2.编辑项目根目录下的.csproj文件,添加版本号(建议): < ...

  9. 【理解】 Error 10053和 Error 10054

    1. 10053 这个错误码的意思是:  A established connection was aborted by the software in your host machine, 一个已建 ...

  10. CSS3动画理解与应用

    CSS3动画理解与应用 Transform:对元素进行变形:Transition:对元素某个属性或多个属性的变化,进行控制(时间等),类似flash的补间动画.但只有两个关键贞.开始,结束.Anima ...