Conturbatio

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 232    Accepted Submission(s): 108

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.

题意是一个棋盘上有很多车,车可以攻击他所属的一行或一列,包括它自己所在的位置。现在有很多询问,每次询问给定一个棋盘内部的矩形,问矩形内部的所有格子是否都被车攻击到?

对自己的智商感到不断怀疑系列。。。判断中间有没有零,求和啊

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#pragma warning(disable:4996)
using namespace std; int row[100005];
int column[100005]; int main()
{
int test,i,j,flag1,flag2;
int n,m,k,q,x,y,x1,x2,y1,y2; scanf("%d",&test); while(test--)
{
scanf("%d%d%d%d",&n,&m,&k,&q); memset(row,0,sizeof(row));
memset(column,0,sizeof(column)); for(i=1;i<=k;i++)
{
scanf("%d%d",&x,&y);
row[x]=1;
column[y]=1;
}
for(i=1;i<=n;i++)
{
row[i]=row[i]+row[i-1];
}
for(i=1;i<=m;i++)
{
column[i]=column[i]+column[i-1];
}
for(i=1;i<=q;i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x2-x1+1==row[x2]-row[x1-1]||y2-y1+1==column[y2]-column[y1-1])
{
puts("Yes");
}
else
{
puts("No");
}
}
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 5480:Conturbatio 前缀和的更多相关文章

  1. hdu 5480 Conturbatio 线段树 单点更新,区间查询最小值

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

  2. hdu 5480(维护前缀和+思路题)

    Conturbatio Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. HDU 5480 Conturbatio

    区间求和不更新,开个数组记录一下前缀和就可以了 #include<cstdio> #include<cstring> #include<cmath> #includ ...

  4. hdu 5480(前缀和)

    题意:如果一个点,则这点的横竖皆被占领,询问矩阵是否全被占领. 思路:将被占领的x,y标记为1,用x表示1 - i的和 如果x轴的差为 x2 - x1 + 1则表示全被占领,y轴同理 #include ...

  5. HDU 1358 (所有前缀中的周期串) Period

    题意: 给出一个字符串,在所有长度大于1的前缀中,求所有的周期至少为2的周期串,并输出一个周期的长度以及周期的次数. 分析: 有了上一题 HDU 3746 的铺垫,这道题就很容易解决了 把next求出 ...

  6. HDU 5714 拍照 前缀和

    拍照 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5714 Description 小明在旅游的路上看到了一条美丽的河,河上有许多船只,有的船只向左 ...

  7. Coprime Sequence (HDU 6025)前缀和与后缀和的应用

    题意:给出一串数列,这串数列的gcd为1,要求取出一个数使取出后的数列gcd最大. 题解:可以通过对数列进行预处理,求出从下标为1开始的数对于前面的数的gcd(数组从下标0开始),称为前缀gcd,再以 ...

  8. hdu 5776 sum 前缀和

    sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submi ...

  9. HDU - 1588 矩阵前缀和

    题意:给定\(k,b,n,m\),求\(\sum_{i=0}^{n-1}f(g(i))\) 其中\(f(i)=f(i-1)+f(i-2),f(1)=1,f(0)=0\),\(g(i)=k*i+b\) ...

随机推荐

  1. Redis的两个典型应用场景

    Redis简介 Redis是目前业界使用最广泛的内存数据存储.相比memcached,Redis支持更丰富的数据结构,例如hashes, lists, sets等,同时支持数据持久化.除此之外,Red ...

  2. go语言的变量和定量

    1.变量: 1.var go 的变量非常灵活引入了关键字var. 如 var v1 int var v2 string var v3 [10]int 在go语言中变量申明有更快捷的办法可以把若干个变量 ...

  3. 多门店4s管理系统

    下载 系统登录用户名与密码:manage/123456

  4. String和Date 互相转换

    1.String ->Date String StrDate = "2012-12-12"; SimpleDateFormat sdf=new SimpleDateForma ...

  5. k8s解析service地址方式

    [root@k8s-master ~]# dig -t A kubernetes.default.svc.cluster.local. @10.96.0.10 ; <<>> D ...

  6. MySQL查询事务 杀死事务

    遇到 com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock 查询: SELECT * FROM inf ...

  7. docker 为镜像添加ssh服务-使用Dockerfile 创建

    首先,基于要添加内容的镜像ubuntu:18.04运行一个容器, 在宿主机(下面步骤是在容器中创建的,应该在宿主机创建进行以下步骤) 一.创建一个工作目录 二.创建Dockerfile 和脚本run. ...

  8. gitbook简单教程

    简介 GitBook 是一个基于 Node.js 的命令行工具,可使用 Github/Git 和 Markdown 来制作精美的电子书.GitBook支持输出以下几种文档格式 静态站点:GitBook ...

  9. Jackson学习笔记

    老版本的Jackson使用的包名为org.codehaus.jackson,而新版本使用的是com.fasterxml.jackson. Jackson主要包含了3个模块: jackson-core ...

  10. Codeforces Round #619 (Div. 2)

    A. Three Strings 题意:给三个长度相同的非空字符串abc,依次将c中的每个字符和a或者b中对应位置的字符进行交换,交换必须进行,问能否使得ab相同. 思路:对于每一个位置,如果三个字符 ...