题目

UVA11297 Census

做法

二维线段树,单点修改,矩阵查询,树套树(\(x,y\)),维护最大值最小值废话

有一点要注意的是:\(x\)树传到\(y\)树里面修改的时候,如果\(x\)树中是叶子节点之间修改,否则在y树中还得拿\(x\)树中的左右儿子来修改

My complete code

#include<bits/stdc++.h>
using namespace std;
typedef int LL;
const LL inf=0x3f3f3f3f,maxn=2009;
LL n,xo,tmx,tmi,q;
LL Mx[maxn][maxn],Mi[maxn][maxn];
bool leaf;
void Modify1(LL now,LL l,LL r,LL c,LL val){
if(l==r){
if(leaf){
Mx[xo][now]=Mi[xo][now]=val; return;
}
Mx[xo][now]=max(Mx[xo<<1][now],Mx[xo<<1|1][now]),
Mi[xo][now]=min(Mi[xo<<1][now],Mi[xo<<1|1][now]);
return;
}
LL mid(l+r>>1);
if(c<=mid) Modify1(now<<1,l,mid,c,val);
else Modify1(now<<1|1,mid+1,r,c,val);
Mx[xo][now]=max(Mx[xo][now<<1],Mx[xo][now<<1|1]),
Mi[xo][now]=min(Mi[xo][now<<1],Mi[xo][now<<1|1]);
}
void Modify2(LL now,LL l,LL r,LL x,LL y,LL val){
if(l==r){
xo=now,leaf=true; Modify1(1,1,n,y,val);
return;
}
LL mid(l+r>>1);
if(x<=mid) Modify2(now<<1,l,mid,x,y,val);
else Modify2(now<<1|1,mid+1,r,x,y,val);
xo=now,leaf=false; Modify1(1,1,n,y,val);
}
void Query1(LL now,LL l,LL r,LL y1,LL y2){
if(y1<=l&&y2>=r){
tmx=max(tmx,Mx[xo][now]),tmi=min(tmi,Mi[xo][now]);
return;
}
LL mid(l+r>>1);
if(y1<=mid) Query1(now<<1,l,mid,y1,y2);
if(y2>mid) Query1(now<<1|1,mid+1,r,y1,y2);
}
void Query2(LL now,LL l,LL r,LL x1,LL x2,LL y1,LL y2){
if(x1<=l&&x2>=r){
xo=now,Query1(1,1,n,y1,y2);
return;
}
LL mid(l+r>>1);
if(x1<=mid) Query2(now<<1,l,mid,x1,x2,y1,y2);
if(x2>mid) Query2(now<<1|1,mid+1,r,x1,x2,y1,y2);
}
int main(){
cin>>n;
for(LL i=1;i<=n;++i)
for(LL j=1;j<=n;++j){
LL val;
cin>>val;
Modify2(1,1,n,i,j,val);
}
cin>>q;
while(q--){
char c;scanf(" %c ",&c);
if(c=='q'){
LL x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
tmx=-inf,tmi=inf;
Query2(1,1,n,x1,x2,y1,y2);
cout<<tmx<<' '<<tmi<<endl;
}else{
LL x,y,val; cin>>x>>y>>val;
Modify2(1,1,n,x,y,val);
}
}return 0;
}

UVA11297 Census的更多相关文章

  1. UVA-11297 Census(线段树套线段树)

    题目大意:二维空间点修改,询问矩形区域最值. 题目分析:还是比较简单的. 代码如下: # include<iostream> # include<cstdio> # inclu ...

  2. 图像变换之Census变换

    图像的Census变换 Census变换属于非参数图像变换的一种,它能够较好地检测出图像中的局部结构特征,如边缘.角点特征等.传统Census变换的基本思想是:在图像区域定义一个矩形窗口,用这个矩形窗 ...

  3. [Machine Learning][The Analytics Edge][Predicting Earnings from Census Data]

    census = read.csv("census.csv")library(caTools)set.seed(2000)spl = sample.split(census$ove ...

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

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

  5. 立体匹配之Census Transform

    1.立体匹配算法主要可分为两大类:基于局部约束和基于全局约束的立体匹配算法. (一)基于全局约束的立体匹配算法:在本质上属于优化算法,它是将立体匹配问题转化为寻找全局能量函数的最优化问题,其代表算法主 ...

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

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

  7. UVA 11297 Census ——二维线段树

    [题目分析] 二维线段树模板题目. 简直就是无比的暴力.时间复杂度为两个log. 标记的更新方式比较奇特,空间复杂度为N^2. 模板题目. [代码] #include <cstdio> # ...

  8. 【机器学习Machine Learning】资料大全

    昨天总结了深度学习的资料,今天把机器学习的资料也总结一下(友情提示:有些网站需要"科学上网"^_^) 推荐几本好书: 1.Pattern Recognition and Machi ...

  9. 【数学】Jersey Politics

                                                            Jersey Politics Time Limit: 1000MS   Memory ...

随机推荐

  1. 基于docker的webrtc开发环境

    在root目录下先放好自定义的constants.py文件再docker run 同时记得修改PUBLIC_IP 可以跨wifi通信 docker pull piasy/apprtc-server d ...

  2. c语言之linux下gettimeofday函数windows替换方案

    * Copyright (C) 2008 mymtom (mymtom@hotmail.com) * All rights reserved. * * Redistribution and use i ...

  3. Python Theano ValueError: y_i value out of bounds

    参考 https://groups.google.com/forum/#!topic/theano-users/tY3fNAPYd9k 这个问题是由于outs的数量没有设置对. 里面写到 “excep ...

  4. windows 32位以及64位的inline hook

    Tips : 这篇文章的主题是x86及x64 windows系统下的inline hook实现部分. 32位inline hook 对于系统API的hook,windows 系统为了达成hotpatc ...

  5. php 工厂方法模式

    #使用工厂方法模式是不知道要创建类的对象有哪些.interface IFactory{ public function CreateOperation();#工厂方法模式只有单个产品 } class ...

  6. 【BZOJ1923】[Sdoi2010]外星千足虫 高斯消元

    [BZOJ1923][Sdoi2010]外星千足虫 Description Input 第一行是两个正整数 N, M. 接下来 M行,按顺序给出 Charles 这M次使用“点足机”的统计结果.每行 ...

  7. cocos2d-x设计模式发掘之三:管理者模式

      作者 firedragonpzy    地址:http://www.firedragonpzy.com.cn/index.php/archives/2103 想必读者一看这个题目又要纳闷了,神马又 ...

  8. Unique Encryption Keys

    The security of many ciphers strongly depends on the fact that the keys are unique and never re-used ...

  9. oracle clob字段去除html标签

    通过正则表达式的方式去除html标签 select regexp_replace(content,'</?[^>]*>|nbsp;|&','') content from T ...

  10. 纯CSS3文字效果推荐

    之前曾经研究过几个纯css实现的文字效果,<CSS文字条纹阴影动画>和<响应式奶油立体字效果>等,今天我们来研究几款文字效果,主要利用text-shadow.webkit内核的 ...