【题目分析】

二维线段树模板题目。

简直就是无比的暴力。时间复杂度为两个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. jmeter分布式测试配置

    jmeter分布式测试 说明:1台8核16G的windows2008的机器,只能器6000个线程,否则效果不是很好:并且负载机器需要做如下设置: 1.打开注册表:regedit 2.HKEY_LOCA ...

  2. C#调用Lame.exe

    string lameEXE = @"D:\lame3.100\lame.exe"; string lameArgs = "-b 128"; string wa ...

  3. Openjudge 1.13-23:区间内的真素数

    总时间限制:  1000ms 内存限制:  65536kB 描述 找出正整数 M 和 N 之间(N 不小于 M)的所有真素数. 真素数的定义:如果一个正整数 P 为素数,且其反序也为素数,那么 P 就 ...

  4. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  5. leetcode_1033. Moving Stones Until Consecutive

    https://leetcode.com/problems/moving-stones-until-consecutive/ 题意:给定3个点,每次从两个端点(位置最小或位置最大)中挑选一个点进行移动 ...

  6. Eclipse 和 MyEclipse 工程描述符

    有时候在一个Java工程里我们需要加入第三方jar包,这时你加入的最好相对路径, 而不是绝对路径.否则你的工程拿到别处就不行运行了.意思就是说你最好把相关的jar放到工程目录下. 对于Web工程来说相 ...

  7. abp viewmodel的写法

    我的写法 public class QuotaCreateOrEditViewModel { public QuotaDto LoanQuota { get; set; } public bool I ...

  8. CPP-基础:函数指针,指针函数,指针数组

    函数指针 函数指针是指向函数的指针变量. 因而“函数指针”本身首先应是指针变量,只不过该指针变量指向函数.这正如用指针变量可指向整型变量.字符型.数组一样,这里是指向函数.如前所述,C在编译时,每一个 ...

  9. Vue的安装并在WebStorm中运行

    一.Vue的安装需要两个支持分别为:nodejs.npm Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境. Node.js 使用了一个事件驱动.非阻塞式 I/O ...

  10. Bootstrap响应式布局(1)

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...