CF1093G.Multidimensional Queries

提高+/省选-

通过率:0%

时间限制:6.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array aa of nn points in kk-dimensional space. Let the distance between two points axa_x and aya_y be ∑i=1k∣ax,i−ay,i∣\sum \limits_{i = 1}^{k} |a_{x, i} - a_{y, i}| (it is also known as Manhattan distance).

You have to process qq queries of the following two types:

  • 11 ii b1b_1 b2b_2 ... bkb_k — set ii-th element of aa to the point (b1,b2,…,bk)(b_1, b_2, \dots, b_k);
  • 22 ll rr — find the maximum distance between two points aia_i and aja_j, where l≤i,j≤rl \le i, j \le r.

给你一个包含 nn 个点的数组 aa,每个点位于 kk 维空间中。定义两个点 axa_x 和 aya_y 之间的距离为 ∑i=1k∣ax,i−ay,i∣\sum \limits_{i = 1}^{k} |a_{x, i} - a_{y, i}|(该距离也称为曼哈顿距离)。

你需要处理 qq 个如下两种类型的查询:

  • 11 ii b1b_1 b2b_2 ... bkb_k —— 将数组 aa 的第 ii 个元素设置为点 (b1,b2,…,bk)(b_1, b_2, \dots, b_k);
  • 22 ll rr —— 在下标满足 l≤i,j≤rl \le i, j \le r 的所有点对 aia_i 和 aja_j 中,求它们之间最大的距离。

输入格式

The first line contains two numbers nn and kk (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤k≤51 \le k \le 5) — the number of elements in aa and the number of dimensions of the space, respectively.

Then nn lines follow, each containing kk integers ai,1a_{i, 1}, ai,2a_{i, 2}, ..., ai,ka_{i, k} (−106≤ai,j≤106-10^6 \le a_{i, j} \le 10^6) — the coordinates of ii-th point.

The next line contains one integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of queries.

Then qq lines follow, each denoting a query. There are two types of queries:

  • 11 ii b1b_1 b2b_2 ... bkb_k (1≤i≤n1 \le i \le n, −106≤bj≤106-10^6 \le b_j \le 10^6) — set ii-th element of aa to the point (b1,b2,…,bk)(b_1, b_2, \dots, b_k);
  • 22 ll rr (1≤l≤r≤n1 \le l \le r \le n) — find the maximum distance between two points aia_i and aja_j, where l≤i,j≤rl \le i, j \le r.

There is at least one query of the second type.

第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤k≤51 \le k \le 5)—— 分别表示数组 aa 的元素个数以及空间的维数。

接下来 nn 行,每行包含 kk 个整数 ai,1a_{i, 1}、ai,2a_{i, 2}、…、ai,ka_{i, k}(−106≤ai,j≤106-10^6 \le a_{i, j} \le 10^6)—— 表示第 ii 个点的坐标。

接下来一行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5)—— 表示查询的个数。

随后 qq 行,每行描述一个查询。查询分为两类:

  • 11 ii b1b_1 b2b_2 … bkb_k(1≤i≤n1 \le i \le n,−106≤bj≤106-10^6 \le b_j \le 10^6)—— 将 aa 的第 ii 个元素更新为点 (b1,b2,…,bk)(b_1, b_2, \dots, b_k);
  • 22 ll rr(1≤l≤r≤n1 \le l \le r \le n)—— 求下标满足 l≤i,j≤rl \le i, j \le r 的所有点对 aia_i 与 aja_j 之间的最大距离。

保证至少存在一个第二类查询。

输出格式

Print the answer for each query of the second type.

打印每个第二类查询的答案。

输入输出样例

  • 输入#1

    5 2
    1 2
    2 3
    3 4
    4 5
    5 6
    7
    2 1 5
    2 1 3
    2 3 5
    1 5 -1 -2
    2 1 5
    1 4 -1 -2
    2 1 5

    输出#1

    8
    4
    4
    12
    10

输入解题思路,AI测评打分。不知道怎么写?

首页