hdu 5480 Conturbatio 线段树 单点更新,区间查询最小值
Conturbatio
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5480
Description
There are many rook on a chessboard, a rook can attack the row and column it belongs, including its own place.
There are also many queries, each query gives a rectangle on the chess board, and asks whether every grid in the rectangle will be attacked by any rook?
Input
The first line of the input is a integer T, meaning that there are T test cases.
Every test cases begin with four integers n,m,K,Q.
K is the number of Rook, Q is the number of queries.
Then K lines follow, each contain two integers x,y describing the coordinate of Rook.
Then Q lines follow, each contain four integers x1,y1,x2,y2 describing the left-down and right-up coordinates of query.
1≤n,m,K,Q≤100,000.
1≤x≤n,1≤y≤m.
1≤x1≤x2≤n,1≤y1≤y2≤m.
Output
For every query output "Yes" or "No" as mentioned above.
Sample Input
2
2 2 1 2
1 1
1 1 1 2
2 1 2 2
2 2 2 1
1 1
1 2
2 1 2 2
Sample Output
Yes
No
Yes
HINT
题意
在一个n \times mn×m的国际象棋棋盘上有很多车(Rook),其中车可以攻击他所属的一行或一列,包括它自己所在的位置。
现在还有很多询问,每次询问给定一个棋盘内部的矩形,问矩形内部的所有格子是否都被车攻击到?
题解:
我是线段树做的,只要统计x1,x2这个区域的最小值和y1 y2这个区域的最小值都不同时为0 就好了
@)1%KBO0HM418$J94$1R.jpg)
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 150001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/*
inline ll read()
{
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;
}
*/
//************************************************************************************** struct data{
int l,r,mn;
}tr[maxn*]; data tr2[maxn*];
void build2(int k,int s,int t)
{
tr2[k].l=s;tr2[k].r=t;
if(s==t){tr2[k].mn=;return;}
int mid=(s+t)>>;
build2(k<<,s,mid);
build2(k<<|,mid+,t);
tr2[k].mn=min(tr2[k<<].mn,tr2[k<<|].mn);
}
int ask2(int k,int s,int t)
{
int l=tr2[k].l,r=tr2[k].r;
if(s==l&&t==r)return tr2[k].mn;
int mid=(l+r)>>;
if(t<=mid)return ask2(k<<,s,t);
if(s>mid)return ask2(k<<|,s,t);
return min(ask2(k<<,s,mid),ask2(k<<|,mid+,t));
}
void update2(int k,int x,int y)
{
int l=tr2[k].l,r=tr2[k].r;
if(l==r){tr2[k].mn=y;return;}
int mid=(l+r)>>;
if(x<=mid)update2(k<<,x,y);
if(x>mid)update2(k<<|,x,y);
tr2[k].mn=min(tr2[k<<].mn,tr2[k<<|].mn);
}
void build(int k,int s,int t)
{
tr[k].l=s;tr[k].r=t;
if(s==t){tr[k].mn=;return;}
int mid=(s+t)>>;
build(k<<,s,mid);
build(k<<|,mid+,t);
tr[k].mn=min(tr[k<<].mn,tr[k<<|].mn);
}
int ask(int k,int s,int t)
{
int l=tr[k].l,r=tr[k].r;
if(s==l&&t==r)return tr[k].mn;
int mid=(l+r)>>;
if(t<=mid)return ask(k<<,s,t);
if(s>mid)return ask(k<<|,s,t);
return min(ask(k<<,s,mid),ask(k<<|,mid+,t));
}
void update(int k,int x,int y)
{
int l=tr[k].l,r=tr[k].r;
if(l==r){tr[k].mn=y;return;}
int mid=(l+r)>>;
if(x<=mid)update(k<<,x,y);
if(x>mid)update(k<<|,x,y);
tr[k].mn=min(tr[k<<].mn,tr[k<<|].mn);
} int main()
{
int t;scanf("%d",&t);
while(t--)
{
int n,m,k,q;
scanf("%d%d%d%d",&n,&m,&k,&q);
build(,,n);
build2(,,m);
for(int i=;i<=k;i++)
{
int x,y;
scanf("%d%d",&x,&y);
update(,x,);
update2(,y,);
}
for(int i=;i<=q;i++)
{
int x1,x2,y1,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1>x2)swap(x1,x2);
if(y1>y2)swap(y1,y2);
int d1 = max(ask(,x1,x2),ask2(,y1,y2));
if(d1==)
printf("Yes\n");
else
printf("No\n");
}
}
return ;
}
hdu 5480 Conturbatio 线段树 单点更新,区间查询最小值的更多相关文章
- HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)
HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...
- hdu 2795 Billboard 线段树单点更新
Billboard Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...
- NYOJ-568/1012//UVA-12299RMQ with Shifts,线段树单点更新+区间查询
RMQ with Shifts 时间限制:1000 ms | 内存限制:65535 KB 难度:3 -> Link1 <- -> Link2 <- 以上两题题意是一样 ...
- hihoCoder week19 RMQ问题再临-线段树 单点更新 区间查询
单点更新 区间查询 #include <bits/stdc++.h> using namespace std; #define m ((l+r)/2) #define ls (rt< ...
- HDU 1166敌兵布阵+NOJv2 1025: Hkhv love spent money(线段树单点更新区间查询)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU 1754.I Hate It-结构体版线段树(单点更新+区间查询最值)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 3308 LCIS(线段树单点更新区间合并)
LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...
- HDU1166(线段树单点更新区间查询)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- CDOJ 1073 线段树 单点更新+区间查询 水题
H - 秋实大哥与线段树 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu Submit S ...
随机推荐
- cisco vpn client for win10 x64 setup package
win10 x64安装cisco vpn client报错,解决方法如下: 1.卸载以前安装的所有cisco vpn client,并重启电脑. 2.运行winfix.exe 3.安装Global V ...
- C语言中的malloc和free
最近在研究php自定义函数的实现,其中php自定义函数在传递参数时,是放到人为的一个栈中,这个跟写C程序时,参数入栈的这个栈还不一样,其中延伸到了 malloc 以及free 有人说在free(p)后 ...
- bzoj4009
这是一道神题,首先我们不难先到整体二分吧 下面的问题就是,求出对于每个水果,有多少盘子是他的子路径 直接考虑不是很容易,我们换个思路,考虑对于每个盘子,哪些水果能包含它 我们假设盘子a,b,dep[a ...
- C# DataGridView绑定数据源的几种常见方式
开始以前,先认识一下WinForm控件数据绑定的两种形式,简单数据绑定和复杂数据绑定. 1. 简单的数据绑定 例1 using (SqlConnection conn = new SqlConnect ...
- SCI杂志分区规则
1区:该期刊的影响因子排名位于其所在学科排名的前5% 2区:该期刊的影响因子排名位于其所在学科排名的前20%但未进入5% 3区:该期刊的影响因子排名位于其所在学科排名的前50%但未进入20%的 4区: ...
- 【Jenkins】Linux搭建Jenkins平台
为了配合上一篇的ant+jenkins做持续集成,需要在linux环境下搭建一个jenkins平台.网上有很多安装的例子,我主要记录一下自己遇到的问题,真真的是特别惆怅的,每次我遇到的问题都格外多. ...
- SQL竖表转横表 / 横表转竖表
竖表转横表 竖表结构: Name Course Grade 张三 语文 75 张三 数学 80 张三 英语 90 李四 语文 95 李四 数学 55 转换后横表结构: Name 语文 数学 英语 张三 ...
- 【译】 AWK教程指南 附录A-Patterns
awk 通过判断 Pattern 的值来决定是否执行其后所对应的Actions.这里列出几种常见的Pattern: A.1 BEGIN BEGIN 为 awk 的保留字,是一种特殊的 Pattern. ...
- 标准的TCP/IP工业以太网-EtherNet/IP
标准的TCP/IP工业以太网-EtherNet/IP 徐智穹以太网具有传输速度高.兼容性好.应用广泛等方面的优势,支持几乎所有流行的网络协议,其中 ...
- [原]SyntaxHighlighter使用笔记
[Date]2013-09-21 [Environment]SyntaxHighlighter 3.0.83 [Author]wintys (wintys@gmail.com) http://wint ...