UVA-11297 Census(线段树套线段树)
题目大意:二维空间点修改,询问矩形区域最值。
题目分析:还是比较简单的。
代码如下:
- # include<iostream>
- # include<cstdio>
- # include<cstring>
- # include<algorithm>
- using namespace std;
- # define LL long long
- # define mid (l+(r-l)/2)
- const int N=500;
- const int INF=0x7fffffff;
- int maxn[N*4+5][N*4+5];
- int minn[N*4+5][N*4+5];
- bool leaf;
- void pushUpY(int id,int rt)
- {
- maxn[id][rt]=max(maxn[id][rt<<1],maxn[id][rt<<1|1]);
- minn[id][rt]=min(minn[id][rt<<1],minn[id][rt<<1|1]);
- }
- void buildY(int id,int rt,int l,int r)
- {
- if(l==r){
- if(leaf){
- int a;
- scanf("%d",&a);
- maxn[id][rt]=minn[id][rt]=a;
- }else{
- maxn[id][rt]=max(maxn[id<<1][rt],maxn[id<<1|1][rt]);
- minn[id][rt]=min(minn[id<<1][rt],minn[id<<1|1][rt]);
- }
- }else{
- buildY(id,rt<<1,l,mid);
- buildY(id,rt<<1|1,mid+1,r);
- pushUpY(id,rt);
- }
- }
- void buildX(int rt,int l,int r,int m)
- {
- if(l==r){
- leaf=true;
- buildY(rt,1,1,m);
- }else{
- buildX(rt<<1,l,mid,m);
- buildX(rt<<1|1,mid+1,r,m);
- leaf=false;
- buildY(rt,1,1,m);
- }
- }
- void updateY(int id,int rt,int l,int r,int p,int v)
- {
- if(l==r){
- if(leaf) maxn[id][rt]=minn[id][rt]=v;
- else{
- maxn[id][rt]=max(maxn[id<<1][rt],maxn[id<<1|1][rt]);
- minn[id][rt]=min(minn[id<<1][rt],minn[id<<1|1][rt]);
- }
- }else{
- if(p<=mid) updateY(id,rt<<1,l,mid,p,v);
- else updateY(id,rt<<1|1,mid+1,r,p,v);
- pushUpY(id,rt);
- }
- }
- void updateX(int rt,int l,int r,int p1,int p2,int v,int m)
- {
- if(l==r){
- leaf=true;
- updateY(rt,1,1,m,p2,v);
- }else{
- if(p1<=mid) updateX(rt<<1,l,mid,p1,p2,v,m);
- else updateX(rt<<1|1,mid+1,r,p1,p2,v,m);
- leaf=false;
- updateY(rt,1,1,m,p2,v);
- }
- }
- void queryY(int id,int rt,int l,int r,int L,int R,int &mx,int &mn)
- {
- if(L<=l&&r<=R){
- mx=max(mx,maxn[id][rt]);
- mn=min(mn,minn[id][rt]);
- }else{
- if(L<=mid) queryY(id,rt<<1,l,mid,L,R,mx,mn);
- if(R>mid) queryY(id,rt<<1|1,mid+1,r,L,R,mx,mn);
- }
- }
- void queryX(int rt,int l,int r,int L,int R,int L1,int R1,int &mx,int &mn,int m)
- {
- if(L<=l&&r<=R){
- queryY(rt,1,1,m,L1,R1,mx,mn);
- }else{
- if(L<=mid) queryX(rt<<1,l,mid,L,R,L1,R1,mx,mn,m);
- if(R>mid) queryX(rt<<1|1,mid+1,r,L,R,L1,R1,mx,mn,m);
- }
- }
- int main()
- {
- int n,q,a,b,c,d;
- char op[2];
- while(~scanf("%d",&n))
- {
- buildX(1,1,n,n);
- scanf("%d",&q);
- while(q--)
- {
- scanf("%s",op);
- if(op[0]=='c'){
- scanf("%d%d%d",&a,&b,&c);
- updateX(1,1,n,a,b,c,n);
- }else if(op[0]=='q'){
- scanf("%d%d%d%d",&a,&b,&c,&d);
- int ansA=-INF,ansB=INF;
- queryX(1,1,n,a,c,b,d,ansA,ansB,n);
- printf("%d %d\n",ansA,ansB);
- }
- }
- }
- return 0;
- }
UVA-11297 Census(线段树套线段树)的更多相关文章
- UVA 11297 Census(二维线段树)
Description This year, there have been many problems with population calculations, since in some cit ...
- bzoj 3196 Tyvj 1730 二逼平衡树(线段树套名次树)
3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1807 Solved: 772[Submit][Stat ...
- [BZOJ 1901] Dynamic Rankings 【树状数组套线段树 || 线段树套线段树】
题目链接:BZOJ - 1901 题目分析 树状数组套线段树或线段树套线段树都可以解决这道题. 第一层是区间,第二层是权值. 空间复杂度和时间复杂度均为 O(n log^2 n). 线段树比树状数组麻 ...
- ZJOI 2017 树状数组(线段树套线段树)
题意 http://uoj.ac/problem/291 思路 不难发现,九条カレン醬所写的树状数组,在查询区间 \([1,r]\) 的时候,其实在查询后缀 \([r,n]\) :在查询 \([l,r ...
- BZOJ4317Atm的树&BZOJ2051A Problem For Fun&BZOJ2117[2010国家集训队]Crash的旅游计划——二分答案+动态点分治(点分树套线段树/点分树+vector)
题目描述 Atm有一段时间在虐qtree的题目,于是,他满脑子都是tree,tree,tree…… 于是,一天晚上他梦到自己被关在了一个有根树中,每条路径都有边权,一个神秘的声音告诉他,每个点到其他的 ...
- hdu-4819-线段树套线段树
http://acm.hdu.edu.cn/showproblem.php?pid=4819 给出一个N*N的矩阵,每次询问一个m*m的子矩阵里的floor((maxv+minv)/2)并把中间的元素 ...
- dfs序+主席树 或者 树链剖分+主席树(没写) 或者 线段树套线段树 或者 线段树套splay 或者 线段树套树状数组 bzoj 4448
4448: [Scoi2015]情报传递 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 588 Solved: 308[Submit][Status ...
- 【vijos】1750 建房子(线段树套线段树+前缀和)
https://vijos.org/p/1750 是不是我想复杂了.... 自己yy了个二维线段树,然后愉快的敲打. 但是wa了两法.......sad 原因是在处理第二维的更新出现了个小问题,sad ...
- [TJOI2017][bzoj4889] 不勤劳的图书管理员 [线段树套线段树]
题面 传送门 思路 考虑两本书的位置交换对答案的贡献: (为了方便描述,用"左边那本"和"右边那本"称呼两本我们要交换的书,"中间那本"是我 ...
- 【bzoj4785】[Zjoi2017]树状数组 线段树套线段树
题目描述 漆黑的晚上,九条可怜躺在床上辗转反侧.难以入眠的她想起了若干年前她的一次悲惨的OI 比赛经历.那是一道基础的树状数组题.给出一个长度为 n 的数组 A,初始值都为 0,接下来进行 m 次操作 ...
随机推荐
- JAVA利用JXL导出/生成 EXCEL
/** * 导出导出采暖市场部收入.成本.利润明细表 * @author JIA-G-Y */ public String exporExcel(String str) { String str=Se ...
- Java防盗链机制
对于防盗链技术,网上提供了很多很多的相关技术,但是不是特别复杂就是效果不好. 这里在网上找到一种思路,就是关于HTTP协议响应头中包含的Referer,告诉服务器我是从哪个页面链接过来的,服务器籍此可 ...
- C++ 高质量编程附录试题
附录B :C++/C试题 本试题仅用于考查C++/C程序员的基本编程技能.内容限于C++/C常用语法,不涉及数据结构.算法以及深奥的语法.考试成绩能反映出考生的编程质量以及对C++/C的理解程度,但不 ...
- VIM 代码折叠
VIM 代码折叠 VIM代码折叠方式可以用"foldmethod"选项来设置,如: set foldmethod=indent 有6种方式来折叠代码 1. manual //手工定 ...
- redis 持久化 如果 AOF 文件出错了,怎么办?
服务器可能在程序正在对 AOF 文件进行写入时停机, 如果停机造成了 AOF 文件出错(corrupt), 那么 Redis 在重启时会拒绝载入这个 AOF 文件, 从而确保数据的一致性不会被破坏. ...
- web应用程序测试方法和测试技术详述
1.界面测试 现在一般人都有使用浏览器浏览网页的经历,用户虽然不是专业人员但是对界面效果的印象是很重要的.如果你注重这方面的测试,那么验证应用程序是否易于使用就非常重要了.很多人认为这是测试中最不重要 ...
- PHPMySQL 中 pdo文件的增删改查
<?php //PDO类的增删改查 try { $pdo = new PDO("mysql:host=localhost;dbname=ooo","root&quo ...
- position 定位
position属性是指本体相对于上级的定位,position又分绝对定位和相对定位.他的默认值是static,意味着元素没有被定位,出现在文档流中应该出现的位置.如果用position来布局页面,父 ...
- C#压缩文件夹
using System;using System.Collections.Generic;using System.Text; ///第三方dllusing ICSharpCode.SharpZip ...
- 手把手教你用python抓网页数据
http://www.1point3acres.com/bbs/thread-83337-1-1.html