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. 配置consul为windows服务

    安装consul并配置为系统服务下载地址https://www.consul.io/downloads.html 配置系统服务1.拷贝consul.exe的目录 如:E:\Consul\consule ...

  2. REST Framework 的用户认证组件

    用户认证流程: 我们要知道这个流程是怎么走的? 认证之后做的什么? 怎么认证?这三个条件 认证流程:就是使用BaseAuthentication这个模块来做认证,判断你登陆成功传递过来的随机字符串是否 ...

  3. [翻译] BAFluidView

    BAFluidView https://github.com/antiguab/BAFluidView This view and it's layer create a 2D fluid anima ...

  4. UINavigationController与UITabBarController相关问题

    UINavigationController与UITabBarController相关问题 UINavigationController与UITabBarController混用是非常常见的,有时候会 ...

  5. 笔记本无密码连接wifi

    用手机可以用wifi万能钥匙破解wifi,就想找电脑版的wifi万能钥匙,然并卵. 就去寻找各种办法,最后找了个巧, 用手机下载wifi万能钥匙连接,并且使用数据线连接上笔记本. 然后手机设置中找到开 ...

  6. php实现简单的单链表

    <?php /** * 建立一个链表,节点的data为数组,记录一个id,完成链表所以操作 */ //结点,结点数据data定义为一个数组,id和value class Node{ public ...

  7. UE4中的AI行为树简单介绍

    UE4引擎中可以实现简单AI的方式有很多,行为树是其中比较常用也很实用的AI控制方式,在官网的学习文档中也有最简单的目标跟踪AI操作教程,笔者在这里只作简单介绍. AIController->和 ...

  8. 如何1秒批量提取电脑文件夹中的所有文件、文件夹名字到txt/excel

    01  在工作,我们经常会遇到这样的情况,有时候我们在一个文件夹中放了很多的文件,或者是这个文件夹中有很多的子文件夹,每一个子文件夹的名字又不同,也没有什么样的规律, 02  但是我们要整理一下这个文 ...

  9. Sequelize-nodejs-3-model definition

    Model definition模型定义 To define mappings between a model and a table, use the define method.定义模型和表之间的 ...

  10. TensorFlow安装-Windows

    参考:https://blog.csdn.net/dou3516/article/details/77836459 一.安装环境 TensorFlow即可以支持CPU,也可以支持CPU+GPU.前者的 ...