Conturbatio

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 786    Accepted Submission(s): 358

Problem 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

Huge input, scanf recommended.

 
Source
 
题意:在一个棋盘上有一些"车",他能够攻击到与它同一行或者同一列的棋盘上的所有的格子,现在给出K个棋子的坐标,然后有Q组询问,每一次询问(x1,y1,x2,y2)这个方格内的所有棋子是否能够全部被攻击到。
题解:维护前缀和,统计 (x1-x2) 这一段区间里面的被攻击到的行的数量,统计(y1-y2)这一段区间里面的被攻击到的列的数量,如果sum(x1~x2) == x2-x1+1 ,那么这段区间全部能够被攻击到,列也就不用考虑了,对列的考虑亦如此。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
const int N = ;
int flag_x[N],flag_y[N];
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
int n,m,k,q;
scanf("%d%d%d%d",&n,&m,&k,&q);
memset(flag_x,,sizeof(flag_x));
memset(flag_y,,sizeof(flag_y));
int x,y;
for(int i=;i<=k;i++){
scanf("%d%d",&x,&y);
flag_x[x] = ;
flag_y[y] = ;
}
for(int i=;i<=n;i++){
flag_x[i]+= flag_x[i-];
}
for(int i=;i<=m;i++){
flag_y[i] += flag_y[i-];
}
while(q--){
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(flag_x[x2]-flag_x[x1-]==x2-x1+||flag_y[y2]-flag_y[y1-]==y2-y1+) printf("Yes\n");
else printf("No\n");
}
}
return ;
}

hdu 5480(维护前缀和+思路题)的更多相关文章

  1. hdu 4647 - Another Graph Game(思路题)

    摘自题解: 若没有边权,则对点权从大到小排序即可.. 考虑边,将边权拆成两半加到它所关联的两个点的点权中即可. ..因为当两个人分别选择不同的点时,这一权值将互相抵消. 代码如下: #include ...

  2. HDU 1271 整数对(思路题)

    假设删除第k位,把整数A表示成如下形式: A = a * 10^(k+1) + b * 10 ^k + c; 则: B = a * 10^k + c; N = A + B = (11*a+b)*10^ ...

  3. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  4. Codeforces1076E. Vasya and a Tree(dfs+离线+动态维护前缀和)

    题目链接:传送门 题目: E. Vasya and a Tree time limit per test seconds memory limit per test megabytes input s ...

  5. BZOJ 1303: [CQOI2009]中位数图(思路题)

    传送门 解题思路 比较好想的思路题.首先肯定要把原序列转化一下,大于\(k\)的变成\(1\),小于\(k\)的变成\(-1\),然后求一个前缀和,还要用\(cnt[]\)记录一下前缀和每个数出现了几 ...

  6. HDU 2802 F(N)(简单题,找循环解)

    题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  7. 51nod P1305 Pairwise Sum and Divide ——思路题

    久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...

  8. POJ 1904 思路题

    思路: 思路题 题目诡异地给了一组可行匹配 肯定有用啊-. 就把那组可行的解 女向男连一条有向边 如果男喜欢女 男向女连一条有向边 跑一边Tarjan就行了 (这个时候 环里的都能选 "增广 ...

  9. BZOJ 3252: 攻略(思路题)

    传送门 解题思路 比较好想的一道思路题,结果有个地方没开\(long\) \(long\) \(wa\)了三次..其实就是模仿一下树链剖分,重新定义重儿子,一个点的重儿子为所有儿子中到叶节点权值最大的 ...

随机推荐

  1. Java代码中获取配置文件(config.properties)中内容的两种方法

    方法千千万,本人暂时只总结了两种方法. (1)config.properties中的内容如图 在applicationContext.xml中配置 <!-- 引入配置文件 --> < ...

  2. 关于 Inno Setup 报木马的问题处理

    用 Inno Setup 生成的安装包总是报木马,尝试了N次之后发现,把 Compression=lzma 改为 Compression=zip 就不会再报了,可能lzma的压缩算法导致delphi的 ...

  3. 剑指Offer - 九度1384 - 二维数组中的查找

    剑指Offer - 九度1384 - 二维数组中的查找2013-11-23 23:23 题目描述: 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个 ...

  4. 《Cracking the Coding Interview》——第8章:面向对象设计——题目8

    2014-04-23 23:49 题目:有个棋牌游戏叫Othello,也叫Reversi.请看游戏规则.中文应该叫黑白棋吧,不常玩儿就是了. 解法:既然这题的规则很清楚,也很清楚,我就写了一个命令行的 ...

  5. (原)C sharp杂谈记事(一)

    题记)最是那一低头的温柔,像一朵睡莲花不胜凉风的娇羞 1)接收 公司的X部门有个APP小项目,APP后台是C sharp的MVC,提供了一个C sharp的web from做管理员操作的后台操作,此项 ...

  6. java初学1

    1.Java主要技术和分支以及应用领域 (1)Java SE Java Platform,Standard Edition,Java SE 以前称为J2SE.它允许开发和部署在桌面.服务器.嵌入式环境 ...

  7. android studio 配置网络代理

    1.首先在vultr网站购买服务器. 然后使用shadowsocksR给服务器配置FQ,再在本地机器配置好shadowsocksR. 参考网址:https://github.com/getlanter ...

  8. 使用ADO.NET 实体数据模型连接MySql

    原文:使用ADO.NET 实体数据模型连接MySql 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/a123_z/article/details/8 ...

  9. hexo 配置文件 实例

    # Hexo Configuration ## Docs: https://hexo.io/docs/configuration.html ## Source: https://github.com/ ...

  10. 如何出发匿名映射呀【log】

    malloc-9711 [002] .... 40794.642938: mm_vmscan_lru_shrink_inactive: nid=0 zid=1 nr_scanned=3 nr_recl ...