题目链接:

  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. ZooKeeperACL机制

    官网:http://zookeeper.apache.org/doc/r3.4.6/zookeeperProgrammers.html#sc_ZooKeeperAccessControl 项目中不同的 ...

  2. command symbol & mac & emoji

    command symbol & mac & emoji how to input command symbol in mac ? https://apple.stackexchang ...

  3. 安装Zookeeper出现Unable to start AdminServer,existing abnormally问题解决方法

    问题如下: 出现这个问题主要是由于8080端口占用,可在zoo.cfg中增加admin.serverPort=没有被占用的端口号解决问题.

  4. linux 关机、重启

    一.重启命令:1.reboot2.shutdown -r now 立刻重启(root用户使用)3.shutdown -r 10 过10分钟自动重启(root用户使用) 4.shutdown -r 20 ...

  5. redis压力测试工具-----redis-benchmark

    redis做压测可以用自带的redis-benchmark工具,使用简单 压测命令:redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 压测需要一段 ...

  6. .Net iTextSharp 生成pdf

    拿别人例子 public ActionResult index() { var ms = new MemoryStream(); #region CreatePDF Document document ...

  7. 再谈 最速下降法/梯度法/Steepest Descent

    转载请注明出处:http://www.codelast.com/ 最速下降法(又称梯度法,或Steepest Descent),是无约束最优化领域中最简单的算法,单独就这种算法来看,属于早就“过时”了 ...

  8. BZOJ4561 JLOI2016圆的异或并(扫描线+平衡树)

    考虑一条扫描线从左到右扫过这些圆.观察某一时刻直线与这些圆的交点,可以发现构成一个类似括号序列的东西,括号的包含关系与圆的包含关系是相同的.并且当扫描线逐渐移动时,括号间的相对顺序不变.于是考虑用se ...

  9. bzoj1683[Usaco2005 Nov]City skyline 城市地平线

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1683 Input 第1行:2个用空格隔开的整数N和W. 第2到N+1行:每行包括2个用空格 ...

  10. Group Anagrams - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Group Anagrams - LeetCode 注意点 字母都是小写的 解法 解法一:用一个字符串表示strs[i]中出现的字母,比如:abc-> ...