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. 解决Android Studio报错:DefaultAndroidProject : Unsupported major.minor version 52.0

    解决办法是你需要将工程根目录build.gradle中的 classpath 'com.android.tools.build:gradle:2.2.0' 更改成 classpath 'com.and ...

  2. spring整合redis缓存,以注解(@Cacheable、@CachePut、@CacheEvict)形式使用

    maven项目中在pom.xml中依赖2个jar包,其他的spring的jar包省略: <dependency> <groupId>redis.clients</grou ...

  3. 大数据服务大比拼:AWS VS. AzureVS.谷歌

    [TechTarget中国原创] 对于企业用户来说,大数据服务是一项较具吸引力的云服务.三大巨头AWS.Azure以及谷歌都在力争夺得头把交椅,但是最后到底是哪一家能够取得王座之战的胜利呢? 云市场正 ...

  4. IDEA调试快捷键

    F9            resume programe 恢复程序 F8            Step Over 相当于eclipse的f6      跳到下一步 Ctrl+Shift+F,全局查 ...

  5. Linq中Count()和Any()引发的效率问题

    1.count和any 今天看了鹤冲天的文章:Linq:切勿使用 Count() > 0 来判断集合非空   有所收获,写下文章总结一下: 先看如下代码: static void Main(st ...

  6. 【志银】Win764位配置Github环境及将代码部署到Github pages-志银强势总结

    (软件及教程下载分享:链接:http://pan.baidu.com/s/1dFysay9 密码:pug0) 1-安装Git-2.9.2-64-bit.exe(解压安装文件,运行安装程序,除了记得修改 ...

  7. 微信公众号开发java框架:wx4j(入门篇)

    导航 入门 http://www.cnblogs.com/2333/p/6617819.html WxServlet介绍 MaterialUtils 素材工具类使用说明 http://www.cnbl ...

  8. 201621123033 《Java程序设计》第2周学习总结

    1. 本周学习总结 ·学习了String类的特点,以及其与字符数组的关系等等. ·常量池的相关概念. ·包装类的特点. 2. 书面作业 1. String-使用Eclipse关联jdk源代码 1.1 ...

  9. 【bzoj4146】[AMPPZ2014]Divisors 数论

    原文地址:http://www.cnblogs.com/GXZlegend/p/6801411.html 题目描述 给定一个序列a[1],a[2],...,a[n].求满足i!=j且a[i]|a[j] ...

  10. GYM - 101147 A.The game of Osho

    题意: 一共有G个子游戏,一个子游戏有Bi, Ni两个数字.两名玩家开始玩游戏,每名玩家从N中减去B的任意幂次的数,直到不能操作判定为输.问谁最终能赢. 题解: 当Bi为奇数的时候,显然Bi的所有次幂 ...