题目链接:

  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. IE userdata 原理 应用 详解

    https://www.cnblogs.com/chyong168/archive/2012/04/24/2467505.html 在Internet Explorer 5中,Microsoft提供了 ...

  2. sqlserver查询数据库中包含某个字段的所有表和所有存储过程

    1.查询包含某字段的所有表 select object_name(id) objName,Name as colName from syscolumns where (name like'%你要查询的 ...

  3. BZOJ 3173 最长上升子序列(树状数组+二分+线段树)

    给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? 由于序列是顺序插入的,所以当前插入的数字对之 ...

  4. Java Junit测试框架

    Java    Junit测试框架 1.相关概念 Ø JUnit:是一个开发源代码的Java测试框架,用于编写和运行可重复的测试.它是用于单元测试框架体系xUnit的一个实例(用于java语言).主要 ...

  5. Qt——线程与定时器

    一.定时器QTimer类 The QTimer class provides repetitive and single-shot timers. The QTimer class provides ...

  6. Cure HDU - 5879(预处理+技巧)

    Cure Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. Lattice Point or Not UVA - 11768(拓展欧几里得)

    原文地址:https://www.cnblogs.com/zyb993963526/p/6783532.html 题意: 给定两个点A(x1,y1)和B(x2,y2),均为0.1的整数倍.统计选段AB ...

  8. 【刷题】BZOJ 1458 士兵占领

    Description 有一个M * N的棋盘,有的格子是障碍.现在你要选择一些格子来放置一些士兵,一个格子里最多可以放置一个士兵,障碍格里不能放置士兵.我们称这些士兵占领了整个棋盘当满足第i行至少放 ...

  9. Java之Stream流

    Stream流的初步学习 初次学习Stream流的学习笔记,学习之前先了解一下函数式接口 概述 API是一个程序向使用者提供的一些方法,通过这些方法就能实现某些功能.所以对于流API来 说,重点是怎么 ...

  10. 2016-2017 National Taiwan University World Final Team Selection Contest (Codeforces Gym) 部分题解

      D 考虑每个点被删除时其他点对它的贡献,然后发现要求出距离为1~k的点对有多少个. 树分治+FFT.分治时把所有点放一起做一遍FFT,然后减去把每棵子树单独做FFT求出来的值. 复杂度$nlog^ ...