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. //qscqesze
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <ctime>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <set>
  9. #include <vector>
  10. #include <sstream>
  11. #include <queue>
  12. #include <typeinfo>
  13. #include <fstream>
  14. #include <map>
  15. typedef long long ll;
  16. using namespace std;
  17. //freopen("D.in","r",stdin);
  18. //freopen("D.out","w",stdout);
  19. #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
  20. #define maxn 150001
  21. #define mod 10007
  22. #define eps 1e-9
  23. //const int inf=0x7fffffff; //无限大
  24. const int inf=0x3f3f3f3f;
  25. /*
  26. inline ll read()
  27. {
  28. int x=0,f=1;char ch=getchar();
  29. while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  30. while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  31. return x*f;
  32. }
  33. */
  34. //**************************************************************************************
  35.  
  36. struct data{
  37. int l,r,mn;
  38. }tr[maxn*];
  39.  
  40. data tr2[maxn*];
  41. void build2(int k,int s,int t)
  42. {
  43. tr2[k].l=s;tr2[k].r=t;
  44. if(s==t){tr2[k].mn=;return;}
  45. int mid=(s+t)>>;
  46. build2(k<<,s,mid);
  47. build2(k<<|,mid+,t);
  48. tr2[k].mn=min(tr2[k<<].mn,tr2[k<<|].mn);
  49. }
  50. int ask2(int k,int s,int t)
  51. {
  52. int l=tr2[k].l,r=tr2[k].r;
  53. if(s==l&&t==r)return tr2[k].mn;
  54. int mid=(l+r)>>;
  55. if(t<=mid)return ask2(k<<,s,t);
  56. if(s>mid)return ask2(k<<|,s,t);
  57. return min(ask2(k<<,s,mid),ask2(k<<|,mid+,t));
  58. }
  59. void update2(int k,int x,int y)
  60. {
  61. int l=tr2[k].l,r=tr2[k].r;
  62. if(l==r){tr2[k].mn=y;return;}
  63. int mid=(l+r)>>;
  64. if(x<=mid)update2(k<<,x,y);
  65. if(x>mid)update2(k<<|,x,y);
  66. tr2[k].mn=min(tr2[k<<].mn,tr2[k<<|].mn);
  67. }
  68. void build(int k,int s,int t)
  69. {
  70. tr[k].l=s;tr[k].r=t;
  71. if(s==t){tr[k].mn=;return;}
  72. int mid=(s+t)>>;
  73. build(k<<,s,mid);
  74. build(k<<|,mid+,t);
  75. tr[k].mn=min(tr[k<<].mn,tr[k<<|].mn);
  76. }
  77. int ask(int k,int s,int t)
  78. {
  79. int l=tr[k].l,r=tr[k].r;
  80. if(s==l&&t==r)return tr[k].mn;
  81. int mid=(l+r)>>;
  82. if(t<=mid)return ask(k<<,s,t);
  83. if(s>mid)return ask(k<<|,s,t);
  84. return min(ask(k<<,s,mid),ask(k<<|,mid+,t));
  85. }
  86. void update(int k,int x,int y)
  87. {
  88. int l=tr[k].l,r=tr[k].r;
  89. if(l==r){tr[k].mn=y;return;}
  90. int mid=(l+r)>>;
  91. if(x<=mid)update(k<<,x,y);
  92. if(x>mid)update(k<<|,x,y);
  93. tr[k].mn=min(tr[k<<].mn,tr[k<<|].mn);
  94. }
  95.  
  96. int main()
  97. {
  98. int t;scanf("%d",&t);
  99. while(t--)
  100. {
  101. int n,m,k,q;
  102. scanf("%d%d%d%d",&n,&m,&k,&q);
  103. build(,,n);
  104. build2(,,m);
  105. for(int i=;i<=k;i++)
  106. {
  107. int x,y;
  108. scanf("%d%d",&x,&y);
  109. update(,x,);
  110. update2(,y,);
  111. }
  112. for(int i=;i<=q;i++)
  113. {
  114. int x1,x2,y1,y2;
  115. scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
  116. if(x1>x2)swap(x1,x2);
  117. if(y1>y2)swap(y1,y2);
  118. int d1 = max(ask(,x1,x2),ask2(,y1,y2));
  119. if(d1==)
  120. printf("Yes\n");
  121. else
  122. printf("No\n");
  123. }
  124. }
  125. return ;
  126. }

hdu 5480 Conturbatio 线段树 单点更新,区间查询最小值的更多相关文章

  1. HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)

    HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...

  2. hdu 2795 Billboard 线段树单点更新

    Billboard Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...

  3. NYOJ-568/1012//UVA-12299RMQ with Shifts,线段树单点更新+区间查询

    RMQ with Shifts 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 ->  Link1  <- -> Link2  <- 以上两题题意是一样 ...

  4. hihoCoder week19 RMQ问题再临-线段树 单点更新 区间查询

    单点更新 区间查询 #include <bits/stdc++.h> using namespace std; #define m ((l+r)/2) #define ls (rt< ...

  5. HDU 1166敌兵布阵+NOJv2 1025: Hkhv love spent money(线段树单点更新区间查询)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  6. HDU 1754.I Hate It-结构体版线段树(单点更新+区间查询最值)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  7. HDU 3308 LCIS(线段树单点更新区间合并)

    LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...

  8. HDU1166(线段树单点更新区间查询)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  9. CDOJ 1073 线段树 单点更新+区间查询 水题

    H - 秋实大哥与线段树 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit S ...

随机推荐

  1. Function 1 - hello world

    Function 1 - hello world Make a simple function called greet that returns the most-famous "hell ...

  2. C++ 空类默认产生成员函数

    class Empty { Empty(){...} //默认构造函数 ~Empty(){...} //默认析构函数 Empty(const Empty&){...} //拷贝构造函数 Emp ...

  3. linux aio

    前几天nginx的0.8.x正式成为stable,然后看了下代码,发现0.8加入了linux native aio的支持,我们知道在linux下有两种aio,一种是glibc实现的aio,这个比较烂, ...

  4. C#编程让Outlook乖乖交出帐户密码

    许多人习惯于让Outlook记住密码,收邮件时便不必每次都输入邮箱密码,一切让Outlook代劳.但时间一长,马虎的人会把自己的邮箱密码忘记,这样就无法重新设置或者登录Web界面收取邮件了.Outlo ...

  5. UVa 11971 (概率) Polygon

    题意: 有一根绳子,在上面随机选取k个切点,将其切成k+1段,求这些线段能够成k+1边形的概率. 分析: 要构成k+1边形,必须最长的线段小于其他k个线段之和才行. 紫书上给出了一种解法,但是感觉理解 ...

  6. 解决angular的post请求后SpringMVC后台接收不到参数值问题的方法

    这是我后台SpringMVC控制器接收isform参数的方法,只是简单的打出它的值: @RequestMapping(method = RequestMethod.POST) @ResponseBod ...

  7. java.sql.DataTruncation: Data truncation

    问题一: 用jdbc插入数据时,当数据库表中某列设置的长度小于要插入的字符的实际长度时就会抛出此异常. 如:数据表中某列char [4],长度为4,插入:"Hello"时,字符&q ...

  8. PostgreSql与sqlserver对比杂记

    PostgreSql与MSSqlServer区别 增删查改没有语法一样. 排序Group Having 聚集函数使用一样 联结查询 ON 子句是最常见的连接条件的类型:它接收一个和 WHERE 子句相 ...

  9. class属性添加多个类

    <html> <head> <style type="text/css"> h1.intro { color:blue; text-align: ...

  10. SharePoint 2010 获取当前用户的权限

    转:http://blog.csdn.net/sygwin_net/article/details/6790500 操作环境:SharePoint 2010 关于SharePoint 的权限架构,具体 ...