UVA - 11297(线段树套线段树)

放个链接在这里:UVA - 11297

This year, there have been many problems with population calculations, since in some cities, there
are many emigrants, or the population growth is very high. Every year the ACM (for Association
for Counting Members) conducts a census in each region. The country is divided into N ∧ 2 regions,
consisting of an N × N grid of regions. Your task is to find the least, and the greatest population in
some set of regions. Since in a single year there is no significant change in the populations, the ACM
modifies the population counts by some number of inhabitants.
Input
In the first line you will find N (0 ≤ N ≤ 500), in following the N lines you will be given N numbers,
wich represent, the initial population of city C[i, j]. In the following line is the number Q (Q ≤ 40000),
followed by Q lines with queries:
There are two possible queries:
• ‘q x1 y1 x2 y2’ which represent the coordinates of the upper left and lower right of where you
must calculate the maximum and minimum change in population.
• ‘c x y v’ indicating a change of the population of city C[x, y] by value v.
Output
For each query, ‘q x1 y1 x2 y2’ print in a single line the greatest and least amount of current population. Separated each output by a space.
Notice: There is only a single test case.
Sample Input

5
1 2 3 4 5
0 9 2 1 3
0 2 3 4 1
0 1 2 4 5
8 5 3 1 4
4
q 1 1 2 3
c 2 3 10
q 1 1 5 5
q 1 2 2 2

Sample Output

9 0
10 0
9 2

题目大意:有一个n*n的矩阵,然后有两种操作,第一种就是查询一个小矩阵中的元素的最大值和最小值,另一种就是我们可以修改矩阵中的一个值,将它修改为val。

解题思路:线段树套线段树,外层维护行,内层维护列,然后修改时先修改内层的值,再修改外层的值,查询时就先让满足外层的条件,然后再去查询满足内层的条件的值。
树套树的题我之前只写过两三道,其实也不怎么熟悉,而且之前怎么写的也有点模糊了,今天写这道题的时候,学长讲了分块的知识点,然后又去找了两个题来做,也写出了许多bug,然后再来做这道题的时候,感觉写的过程挺顺利的(还好之前的理解还没忘),就是一边写一边想之前是怎么写的,然后也自己写出来了,而且还没怎么调试,一发A[笑],不过以后还是要多学一些树套树,今天看到分块的题解中有很多都写了点分治和树套树。呜呜呜,wtcl。
代码:

#pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <random>
#include <time.h>
using namespace std;
#define int long long
#define ls root<<1
#define rs root<<1|1
const int maxn = 666;
const int inf = 0x3f3f3f3f;
std::mt19937 rnd(233);
struct Node
{
   
    int l, r, date1, date2;
};
struct tree{
   
    int l, r;
    Node node[maxn<<2];
} t[maxn << 2];
int n;
inline void build(int rt,Node <
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值