题目链接:

  https://codeforces.com/contest/1093/problem/G

题目:

题意:

  在k维空间中有n个点,每次给你两种操作,一种是将某一个点的坐标改为另一个坐标,一种操作是查询[l,r]中曼哈顿距离最大的两个点的最大曼哈顿距离。

思路:

  对于曼哈顿距离,我们将其绝对值去掉会发现如下规律(以二维为例):

    

  故这题我们可以用线段树来维护[l,r]中上述每种情况的最大值和最小值,用二进制来枚举xy的符号(1为正,0为负),最后答案是 每种情况中区间最大值-区间最小值 的最大值。

代码实现如下:

 #include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pli;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://code//in.txt", "r", stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-;
const int mod = ;
const int maxn = 2e5 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int n, k, q, op, x, l, r;
int a[maxn][], num[]; struct node {
int l, r, mx, mn;
}segtree[maxn<<][]; void push_up(int rt, int pp) {
segtree[rt][pp].mx = max(segtree[lson][pp].mx, segtree[rson][pp].mx);
segtree[rt][pp].mn = min(segtree[lson][pp].mn, segtree[rson][pp].mn);
} void build(int rt, int l, int r, int pp) {
segtree[rt][pp].l = l, segtree[rt][pp].r = r;
segtree[rt][pp].mx = segtree[rt][pp].mn = ;
if(l == r) {
for(int i = ; i < k; i++) {
if(pp & (<<i)) {
segtree[rt][pp].mx += a[l][i];
segtree[rt][pp].mn += a[l][i];
} else {
segtree[rt][pp].mx -= a[l][i];
segtree[rt][pp].mn -= a[l][i];
}
}
return;
}
int mid = (l + r) >> ;
build(lson, l, mid, pp);
build(rson, mid + , r, pp);
push_up(rt, pp);
} void update(int rt, int pos, int pp) {
if(segtree[rt][pp].l == segtree[rt][pp].r) {
segtree[rt][pp].mx = segtree[rt][pp].mn = ;
for(int i = ; i < k; i++) {
if(pp & (<<i)) {
segtree[rt][pp].mx += num[i];
segtree[rt][pp].mn += num[i];
} else {
segtree[rt][pp].mx -= num[i];
segtree[rt][pp].mn -= num[i];
}
}
return;
}
int mid = (segtree[rt][pp].l + segtree[rt][pp].r) >> ;
if(pos <= mid) update(lson, pos, pp);
else update(rson, pos, pp);
push_up(rt, pp);
} int query(int rt, int l, int r, int pp, int op) {
if(segtree[rt][pp].l >= l && segtree[rt][pp].r <= r) {
if(op == ) {
return segtree[rt][pp].mx;
} else {
return segtree[rt][pp].mn;
}
}
int mid = (segtree[rt][pp].l + segtree[rt][pp].r) >> ;
if(r <= mid) return query(lson, l, r, pp, op);
else if(l > mid) return query(rson, l, r, pp, op);
else {
if(op == ) return max(query(lson, l, mid, pp, op), query(rson, mid + , r, pp, op));
else return min(query(lson, l, mid, pp, op), query(rson, mid + , r, pp, op));
}
} int main(){
#ifndef ONLINE_JUDGE
FIN;
#endif
scanf("%d%d", &n, &k);
for(int i = ; i <= n; i++) {
for(int j = ; j < k; j++) {
scanf("%d", &a[i][j]);
}
}
for(int i = ; i < (<<k); i++) {
build(, , n, i);
}
scanf("%d", &q);
while(q--) {
scanf("%d", &op);
if(op == ) {
scanf("%d", &x);
for(int i = ; i < k; i++) {
scanf("%d", &num[i]);
}
for(int i = ; i <(<<k); i++) {
update(, x, i);
}
} else {
scanf("%d%d", &l, &r);
int mx = -inf;
for(int i = ; i < (<<k); i++) {
mx = max(mx, query(, l, r, i, ) - query(, l, r, i, ));
}
printf("%d\n", mx);
}
}
return ;
}

Multidimensional Queries(二进制枚举+线段树+Educational Codeforces Round 56 (Rated for Div. 2))的更多相关文章

  1. Educational Codeforces Round 56 (Rated for Div. 2) E(1093E) Intersection of Permutations (树套树,pb_ds)

    题意和分析在之前的链接中有:https://www.cnblogs.com/pkgunboat/p/10160741.html 之前补题用三维偏序的cdq的分治A了这道题,但是感觉就算比赛再次遇到类似 ...

  2. Educational Codeforces Round 56 (Rated for Div. 2)

    涨rating啦.. 不过话说为什么有这么多数据结构题啊,难道是中国人出的? A - Dice Rolling 傻逼题,可以用一个三加一堆二或者用一堆二,那就直接.. #include<cstd ...

  3. Educational Codeforces Round 56 (Rated for Div. 2) D. Beautiful Graph 【规律 && DFS】

    传送门:http://codeforces.com/contest/1093/problem/D D. Beautiful Graph time limit per test 2 seconds me ...

  4. Educational Codeforces Round 56 (Rated for Div. 2) ABCD

    题目链接:https://codeforces.com/contest/1093 A. Dice Rolling 题意: 有一个号数为2-7的骰子,现在有一个人他想扔到几就能扔到几,现在问需要扔多少次 ...

  5. Educational Codeforces Round 56 (Rated for Div. 2) D

    给你一个无向图 以及点的个数和边  每个节点只能用1 2 3 三个数字 求相邻 两个节点和为奇数   能否构成以及有多少种构成方法 #include<bits/stdc++.h> usin ...

  6. Educational Codeforces Round 56 (Rated for Div. 2) F - Vasya and Array dp好题

    F - Vasya and Array dp[ i ][ j ] 表示用了前 i 个数字并且最后一个数字是 j 的方案数. dp[ i ][ j ] = sumdp [i - 1 ][ j ], 这样 ...

  7. Educational Codeforces Round 56 (Rated for Div. 2) F. Vasya and Array

    题意:长度为n的数组,数组中的每个元素的取值在1-k的范围内或者是-1,-1代表这个元素要自己选择一个1-k的数字去填写,然后要求填完的数组中不能出现连续长度大于len的情况,询问填空的方案数. 题解 ...

  8. Educational Codeforces Round 56 (Rated for Div. 2) D. Beautiful Graph (二分图染色)

    题意:有\(n\)个点,\(m\)条边的无向图,可以给每个点赋点权\({1,2,3}\),使得每个点连的奇偶不同,问有多少种方案,答案对\(998244353\)取模. 题解:要使得每个点所连的奇偶不 ...

  9. [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)

    [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...

随机推荐

  1. JS单例模式在工作中的使用

    为了尽可能的减少全局变量的污染,在写js的时候可以采用单例模式,形式如下: 比如有一个js叫demo.js,那么我们可以在js里这样写: var demo = {} 这样做的目的是将整个js当成一个对 ...

  2. [百度贴吧]10GB 通信线缆

    现在,即使光纤通信能够带来最低延迟的优势,但是许多IT部门依然在10G以太网(10G bE)中使用铜缆布线,来实现交换机和交换机或者和服务器之间的连接.目前主要有两种主要的铜缆布线技术应用在10 Gb ...

  3. python web调用docker-py

    在 /etc/init.d/docker的start()函数末尾加入:chmod 777 /var/run/docker.sock 否则web程序会没有权限去操作  

  4. SpringBoot(十三)_springboot上传Excel并读取excel中的数据

    今天工作中,发现同事在整理数据,通过excel上传到数据库.所以现在写了篇利用springboot读取excel中的数据的demo.至于数据的进一步处理,大家肯定有不同的应用场景,自行修改 pom文件 ...

  5. delphi如何检索adoquery里面某一列存在的重复行?

    var IsHave:Boolean; begin adoquery.first; while(not adoquery.eof) do begin if(adoquery.fieldbyname(' ...

  6. MySQL中varchar最大长度是多少

    一. varchar存储规则: 4.0版本以下,varchar(20),指的是20字节,如果存放UTF8汉字时,只能存6个(每个汉字3字节) 5.0版本以上,varchar(20),指的是20字符,无 ...

  7. Dcoker中启动mysql,并实现root远程访问

    mysql容器的运行 下载mysql 5.7.19的镜像 docker pull mysql:5.7.19 运行mysql容器,端口映射为 10036 docker run --name mysql5 ...

  8. Netty简单使用

    目录 丢弃服务器 DiscardServerHandler DiscardServer 测试 应答服务器 时间服务器 TimeServerHandler TimeClient TimeClientHa ...

  9. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

    Problem Statement      You are given the ints perimeter and area. Your task is to find a triangle wi ...

  10. LOJ #143. 质数判定

    题目描述 判定输入的数是不是质数. 输入格式 若干行,一行一个数 x. 行数不超过 1.5×104​​. 输出格式 对于输入的每一行,如果 x 是质数输出一行 Y,否则输出一行 N. 样例 样例输入 ...