题目链接:

  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. [转帖]HDD磁盘,非4K无以致远

    https://blog.csdn.net/swingwang/article/details/54880918 机械硬盘的未来要靠高容量作为依托,在财报中,希捷表示未来18个月内它们将推出14和16 ...

  2. .NET 切面编程 PostSharp

    目录 概念 实现方式 .Net平台的切面实现 PostSharp示例 概念 Aspect-Oriented Programming(AOP):想想OOP是不是有些熟悉,AOP翻译过来的意思就是面向切面 ...

  3. jdbc -- 001 -- 一般方式创建数据库连接(oracle/mysql)

    连接数据库步骤: 1. 注册驱动(只做一次) 2. 建立连接(Connection) 3. 创建执行SQL的语句(Statement) 4. 执行语句 5. 处理执行结果(ResultSet) 6. ...

  4. 【uoj#280】[UTR #2]题目难度提升 对顶堆+STL-set

    题目描述 给出 $n$ 个数 $a_1,a_2,...,a_n$ ,将其排为序列 $\{p_i\}$ ,满足 $\{前\ i\ 个数的中位数\}$ 单调不降.求字典序最大的 $\{p_i\}$ . 其 ...

  5. Robot Framework 的安装配置和简单的实例介绍

    Robot Framework 介绍 Robot Framework 是一款基于 Python 的功能自动化测试框架.它具备良好的可扩展性,支持关键字驱动,可以同时测试多种类型的客户端或者接口,可以进 ...

  6. Python实现双色球和大乐透摇奖

    实现代码: # code by kadycui # 模块引用 import random def select(): print('\n') print('请选择彩票种类') print('双色球输入 ...

  7. Stack Overflow上关于Java Collections的几个常见问题

    下面列出Stack Overflow上最常见的几个关于Java Collections的问题并给出答案. 1. 什么时候用LinkedList,什么时候用ArrayList? ArrayList是使用 ...

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

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

  9. Cobalt Strike 3.13的新功能

    Cobalt Strike 3.13现已推出.此版本添加了TCP Beacong,进程参数欺骗,并将Obfuscate和Sleep功能扩展到SMB和TCP Beacons. TCP Beacon Co ...

  10. 前端学习 -- Css

    Css:Cascading Style Sheets CSS叫做层叠样式表,用来设置页面中元素的样式.背景颜色.字体颜色.字体大小... 编写位置: 1,内联样式: 将样式编写到标签的style属性中 ...