VK Cup 2015 - Round 1 E. Rooks and Rectangles 线段树 定点修改,区间最小值
E. Rooks and Rectangles
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://codeforces.com/problemset/problem/524/E
Description
Input
Output
Sample Input
1 1
3 2
2 3
2 3 2 3
2 1 3 3
1 2 2 3
Sample Output
YES
NO
HINT
Picture to the sample: For the last area the answer is "NO", because cell (1, 2) cannot be hit by a rook.
题意
题解:
维护两个数据结构分别表示前i行里第几列是否被覆盖到和前i列里第j行是否被覆盖到
代码:
//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 500001
#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;
}
int buf[10];
inline void write(int i) {
int p = 0;if(i == 0) p++;
else while(i) {buf[p++] = i % 10;i /= 10;}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
printf("\n");
}
*/
//**************************************************************************************
int a[maxn],n,m,k,q;;
struct node
{
int x,y;
};
node p[maxn];
struct pp
{
int x1,y1,x2,y2,id;
};
pp que[maxn]; void updata(int xx, int L, int R, int x, int val)
{
if(L==R)
{
a[xx]=val;
return;
}
int M=(L+R)>>;
if(x <= M)
updata(xx*,L,M,x,val);
else
updata(xx*+,M+,R,x,val);
a[xx]=min(a[xx*], a[xx*+]);
}
int query(int x, int L, int R, int l, int r)
{
if(l<=L&&R<=r)
return a[x];
int M=(L+R)>>;
if(r<=M)
return query(x*,L,M,l,r);
else if(l>M)
return query(x*+,M+,R,l,r);
else
return min(query(x*,L,M,l,r), query(x*+,M+,R,l,r));
}
bool cmp(node x,node y)
{
return x.x<y.x;
}
bool cmp1(pp x,pp y)
{
return x.x2<y.x2;
}
int ans[maxn];
void solve()
{
memset(a,,sizeof(a));
int pic=;
for(int i=;i<q;i++)
{
while(pic<k&&p[pic].x<=que[i].x2)
{
updata(,,m,p[pic].y,p[pic].x);
pic++;
}
if(query(,,m,que[i].y1,que[i].y2)>=que[i].x1)
ans[que[i].id]=;
}
}
void change()
{
swap(n,m);
for(int i=;i<k;i++)
swap(p[i].x,p[i].y);
sort(p,p+k,cmp);
for(int i=;i<q;i++)
{
swap(que[i].x1,que[i].y1);
swap(que[i].x2,que[i].y2);
}
sort(que,que+q,cmp1);
}
int main()
{ scanf("%d%d%d%d",&n,&m,&k,&q);
for(int i=;i<k;i++)
scanf("%d%d",&p[i].x,&p[i].y);
sort(p,p+k,cmp);
for(int i=;i<q;i++)
{
scanf("%d%d%d%d",&que[i].x1,&que[i].y1,&que[i].x2,&que[i].y2);
que[i].id=i;
}
sort(que,que+q,cmp1);
solve();
change();
solve();
for(int i=;i<q;i++)
{
if(ans[i])
puts("YES");
else
puts("NO");
}
}
VK Cup 2015 - Round 1 E. Rooks and Rectangles 线段树 定点修改,区间最小值的更多相关文章
- VK Cup 2015 - Round 1 -E. Rooks and Rectangles 线段树最值+扫描线
题意: n * m的棋盘, k个位置有"rook"(车),q次询问,问是否询问的方块内是否每一行都有一个车或者每一列都有一个车? 满足一个即可 先考虑第一种情况, 第二种类似,sw ...
- Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!
VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题
E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp
题目链接: http://codeforces.com/problemset/problem/533/B B. Work Group time limit per test2 secondsmemor ...
- VK Cup 2015 - Round 2 E. Correcting Mistakes —— 字符串
题目链接:http://codeforces.com/contest/533/problem/E E. Correcting Mistakes time limit per test 2 second ...
- Codeforces 524E Rooks and Rectangles 线段树
区域安全的check方法就是, 每行都有哨兵或者每列都有哨兵,然后我们用y建线段树, 维护在每个y上的哨兵的x的最值就好啦. #include<bits/stdc++.h> #define ...
- VK Cup 2012 Round 3 (Unofficial Div. 2 Edition)
VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) 代码 VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) A ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!
Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...
- HDU 5475(2015 ICPC上海站网络赛)--- An easy problem(线段树点修改)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5475 Problem Description One day, a useless calculato ...
随机推荐
- Linux实用命令之xdg-open
为什么要介绍 xdg-open 呢,得先从需求说起. 一般在控制台中,可以使用命令操作各式文本文件.但难以避免,需要操作一些非文本文件,如 pdf,doc 等. 此时,一般的做法是,打开文件管理器,再 ...
- ubuntu下中文输入法的配置,建议用fcitx
Fcitx [ˈfaɪtɪks] 是一个支持扩展的输入法框架.它有自己维护的三个输入法,拼音,区位和码表:还支持其他引擎,rime 中州韵,google-pinyin,sunpinyin.Fcitx ...
- ahttp
# -*- coding: utf-8 -*- # @Time : 2018/8/20 14:35 # @Author : cxa # @File : chttp.py # @Software: Py ...
- curl错误码77 及 升级libcurl
今天碰到一个问题,curl请求返回错误码77错误 还给出了官网地址,网上查到77对应的是CURLE_SSL_CACERT_BADFILE 想起了刚默认更新了libcurl,于是有手工安装了一下c ...
- Python中raw_input() & input() 的功能对比
raw_input的功能是方便的从控制台读入数据. input与raw_input都是Python的内建函数,实现与用户的交互,但是功能不同. 一.raw_input 下面介绍让raw_input的 ...
- web项目更改文件后缀,隐藏编程语言
从Java EE5.0开始,<servlet-mapping>标签就可以配置多个<url-pattern>.例如可以同时将urlServlet配置一下多个映射方式: <s ...
- 保存进程的pid 文件目录/var/run/
http://blog.ddup.us/?p=110 http://blog.csdn.net/fyinsonw/article/details/4113124 首先声明这不是愚人节消息,事实上这个消 ...
- hive(七)hive-运行方式、GUI接口、权限管理
1.Hive运行方式: 命令行方式cli:控制台模式 脚本运行方式(实际生产环境中用最多) JDBC方式:hiveserver2 web GUI接口 (hwi.hue等) 1.1Hive在CLI模 ...
- [你必须知道的.NET]第十七回:貌合神离:覆写和重载
本文将介绍以下内容: 什么是覆写,什么是重载 覆写与重载的区别 覆写与重载在多态特性中的应用 1. 引言 覆写(override)与重载(overload),是成就.NET面向对象多态特性的基本技术之 ...
- DotNetOpenAuth实践之WCF资源服务器配置
系列目录: DotNetOpenAuth实践系列(源码在这里) 上一篇我们写了一个OAuth2的认证服务器,我们也获取到access_token,那么这个token怎么使用呢,我们现在就来揭开 一般获 ...