【题目分析】

二维线段树模板题目。

简直就是无比的暴力。时间复杂度为两个log。

标记的更新方式比较奇特,空间复杂度为N^2。

模板题目。

【代码】

#include <cstdio>
#include <cstring>
//#include <cmath>
#include <cstdlib> #include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 505
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i) void Finout()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
} int Getint()
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
} int mx[maxn<<2][maxn<<2],mn[maxn<<2][maxn<<2],rt[maxn<<2],ma[maxn][maxn],n;
int x,y,c,tot=0,x1,x2,y1,y2; void pushup(int rt,int o)
{
mx[rt][o]=max(mx[rt][o<<1],mx[rt][o<<1|1]);
mn[rt][o]=min(mn[rt][o<<1],mn[rt][o<<1|1]);
} void update(int rt,int o,int l,int r)
{
// printf("update %d %d %d %d\n",rt,o,l,r);
if (l==r)
{
mx[rt][o]=max(mx[rt<<1][o],mx[rt<<1|1][o]);
mn[rt][o]=min(mn[rt<<1][o],mn[rt<<1|1][o]);
return;
}
int mid=l+r>>1;
if (y<=mid) update(rt,o<<1,l,mid);
else update(rt,o<<1|1,mid+1,r);
pushup(rt,o);
} void push(int rt,int o,int l,int r)
{
if (l==r)
{
mx[rt][o]=mn[rt][o]=c;
return ;
}
int mid=l+r>>1;
if (y<=mid) push(rt,o<<1,l,mid);
else push(rt,o<<1|1,mid+1,r);
pushup(rt,o);
} void modi(int o,int l,int r)
{
if (l==r){push(o,1,1,n);return;}
int mid=l+r>>1;
if (x<=mid) modi(o<<1,l,mid);
else modi(o<<1|1,mid+1,r);
update(o,1,1,n);
} char opt[11];int amx,amn,q; void queryy(int rt,int o,int l,int r)
{
// printf("queryy %d %d %d %d\n",rt,o,l,r);
if (y1<=l&&r<=y2)
{
amx=max(amx,mx[rt][o]);
amn=min(amn,mn[rt][o]);
return ;
}
int mid=l+r>>1;
if (y1<=mid) queryy(rt,o<<1,l,mid);
if (y2>mid) queryy(rt,o<<1|1,mid+1,r);
} void queryx(int o,int l,int r)
{
// printf("query x %d %d %d\n",o,l,r);
if (x1<=l&&r<=x2){ return queryy(o,1,1,n); }
int mid=l+r>>1;
if (x1<=mid) queryx(o<<1,l,mid);
if (x2>mid) queryx(o<<1|1,mid+1,r);
} int main()
{
memset(mx,-0x3f,sizeof mx);
memset(mn, 0x3f,sizeof mn);
Finout();
n=Getint();
F(i,1,n) F(j,1,n)
{
x=i;y=j;
c=ma[i][j]=Getint();
modi(1,1,n);
}
// cout<<mx[1][1]<<" "<<mn[1][1]<<endl;
q=Getint();
F(i,1,q)
{
scanf("%s",opt);
if (opt[0]=='c')
{
x=Getint(); y=Getint(); c=Getint();
modi(1,1,n);
}
else
{
x1=Getint(); y1=Getint(); x2=Getint(); y2=Getint();
amx=-inf,amn=inf;
queryx(1,1,n);
printf("%d %d\n",amx,amn);
}
}
}

  

UVA 11297 Census ——二维线段树的更多相关文章

  1. UVa 11297 Census (二维线段树)

    题意:给定上一个二维矩阵,有两种操作 第一种是修改 c x y val 把(x, y) 改成 val 第二种是查询 q x1 y1 x2 y2 查询这个矩形内的最大值和最小值. 析:二维线段树裸板. ...

  2. UVA 11297 Census(二维线段树)

    Description This year, there have been many problems with population calculations, since in some cit ...

  3. UVA 11297 线段树套线段树(二维线段树)

    题目大意: 就是在二维的空间内进行单个的修改,或者进行整块矩形区域的最大最小值查询 二维线段树树,要注意的是第一维上不是叶子形成的第二维线段树和叶子形成的第二维线段树要  不同的处理方式,非叶子形成的 ...

  4. POJ2155 Matrix二维线段树经典题

    题目链接 二维树状数组 #include<iostream> #include<math.h> #include<algorithm> #include<st ...

  5. HDU 1823 Luck and Love(二维线段树)

    之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #inclu ...

  6. poj 2155:Matrix(二维线段树,矩阵取反,好题)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17880   Accepted: 6709 Descripti ...

  7. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

  8. POJ 2155 Matrix (二维线段树)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17226   Accepted: 6461 Descripti ...

  9. HDU 4819 Mosaic (二维线段树)

    Mosaic Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total S ...

随机推荐

  1. 带有res资源文件的项目 需要导成jar包 供别人使用的解决方法

    比如说自己的成品项目,名字是MyObject,需要导出成jar包,让别人的项目调用,但是自己的项目还包含有图片.layout布局.libs里面的依赖包等等: 步骤: 1.MyObject项目需要“is ...

  2. Android的开机流程及对应源码位置分析

    1.系统引导bootloader 1)源码:bootable/bootloader/* 2)说明:加电后,CPU将先执行bootloader程序,此处有三种选择 a)开机按Camera+Power启动 ...

  3. MD5 介绍

    MD5(单向散列算法)的全称是Message-Digest Algorithm 5(信息-摘要算法),经MD2.MD3和MD4发展而来.MD5算法的使用不需要支付任何版权费用. MD5功能: 输入任意 ...

  4. python中中括号中的负数

    >>> a="a,b,c,d,e">>> a.split(",")[0:2]['a', 'b']>>> a ...

  5. Java动态代理之InvocationHandler最简单的入门教程

    网上关于Java的动态代理,Proxy和InvocationHandler这些概念有讲解得非常高深的文章.其实这些概念没有那么复杂.现在咱们通过一个最简单的例子认识什么是InvocationHandl ...

  6. (转)SpringMVC学习(五)——SpringMVC的参数绑定

    http://blog.csdn.net/yerenyuan_pku/article/details/72511611 SpringMVC中的参数绑定还是蛮重要的,所以单独开一篇文章来讲解.本文所有案 ...

  7. java web.xml被文件加载过程及加载顺序小结

    web.xml加载过程(步骤): 1.启动WEB项目的时候,容器(如:Tomcat)会去读它的配置文件web.xml.读两个节点: <listener></listener> ...

  8. postman使用--构建工作流和newman

    构建工作流 在使用“Collection Runner”的时候,集合中的请求执行顺序就是请求在Collection中的显示排列顺序.但是,有的时候我们不希望请求按照这样的方式去执行,可能是执行完第一个 ...

  9. 如何用纯 CSS 创作阶梯文字特效

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/MXYBEM 可交互视频教 ...

  10. perl 对ENV环境变量的使用

    1.hash 方式访问. %ENV  key为环境变量名,value为环境变量值 2.调用ENV模块 . use Env qw(PATH); print "path is $ENV{path ...