Codeforces Round #439 (Div. 2) E. The Untended Antiquity
E. The Untended Antiquity
题目链接http://codeforces.com/contest/869/problem/E
解题心得:
1、1,x1,y1,x2,y2 以(x1,y1)为左上角(x2,y2)为右下角的矩形,四边建墙。
2,x1,y1,x2,y2 以(x1,y1)为左上角(x2,y2)为右下角的矩形,拆除墙(肯定存在)。
3,x1,y1,x2,y2问是否可以从(x1,y1)走到(x2,y2)(没墙阻隔)。
2、先要标记每个点的状态,将用墙围起来的部分赋予一个值,如果两个点的值相同说明在同一个墙内,或者都没有墙阻拦,但是怎么赋予一个值能够代表这个点的状态,这就要hash,让不同的围困情况有不同的状态值。
3、hash出状态值之后需要标记,遍历肯定会超时,这就需要使用树状数组,二维的树状数组,和一维用法一样。在使用树状数组的时候要注意一下边界的问题
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3000;
const int _hash = 233;
typedef long long ll;
ll maps[maxn][maxn];
ll n,m,q;
ll lowbit(ll x)
{
return x&-x;
}
void updata(ll x,ll y,ll val)
{
for(ll i=x; i<=n; i+=lowbit(i))
for(ll j=y; j<=m; j+=lowbit(j))
maps[i][j] += val;
}
void updata(ll x1,ll y1,ll x2,ll y2,ll val)
{
//需要注意一下边界的问题
updata(x1,y1,val);
updata(x1,y2+1,-val);
updata(x2+1,y1,-val);
updata(x2+1,y2+1,val);
}
ll query(ll x,ll y)
{
ll ans = 0;
for(ll i=x;i;i-=lowbit(i))
for(ll j=y;j;j-=lowbit(j))
ans += maps[i][j];
return ans;
}
void query(ll x1,ll y1,ll x2,ll y2)
{
ll ans1,ans2;
ans1 = ans2 = 0;
ans1 = query(x1,y1);
ans2 = query(x2,y2);
if(ans1 == ans2)
printf("Yes\n");
else
printf("No\n");
}
int main()
{
scanf("%lld%lld%lld",&n,&m,&q);
while(q--)
{
ll mark,x1,x2,y1,y2;
scanf("%lld%lld%lld%lld%lld",&mark,&x1,&y1,&x2,&y2);
ll temp = 1;
//hash
temp = temp*_hash + x1;
temp = temp*_hash + x2;
temp = temp*_hash + y1;
temp = temp*_hash + y2;
if(mark == 2)//拆除状态是建立状态的倒数
temp = -temp;
else if(mark == 3)
{
query(x1,y1,x2,y2);
continue;
}
updata(x1,y1,x2,y2,temp);
}
}
Codeforces Round #439 (Div. 2) E. The Untended Antiquity的更多相关文章
- Codeforces Round #439 (Div. 2)【A、B、C、E】
Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) 题解
题目链接 Round 439 div2 就做了两道题TAT 开场看C题就不会 然后想了好久才想到. 三种颜色挑出两种算方案数其实是独立的,于是就可以乘起来了. E题想了一会有了思路,然后YY出了一种 ...
- Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...
- Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
- Codeforces Round #439 (Div. 2)
A. The Artful Expedient 题目链接:http://codeforces.com/contest/869/problem/A 题目意思:给你两个数列,各包含n个数,现在让你从上下两 ...
- 「日常训练」The Intriguing Obsession(CodeForces Round #439 Div.2 C)
2018年11月30日更新,补充了一些思考. 题意(CodeForces 869C) 三堆点,每堆一种颜色:连接的要求是同色不能相邻或距离必须至少3.问对整个图有几种连接方法,对一个数取模. 解析 要 ...
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
C. The Intriguing Obsession 题目链接http://codeforces.com/contest/869/problem/C 解题心得: 1.由于题目中限制了两个相同 ...
随机推荐
- 解决 mac zsh 所有命令失效
上面的没啥用, 直接看分割线吧, 上面的是第一次遇到这个问题, 没有解决.. zsh: command not found: 参考: https://www.jiloc.com/43492.html ...
- Springboot日志配置探索(主要看logback)(二)
这篇博客主要是讲在Springboot中扩展的日志框架的配置,也是主要讲logback 8 继续看文档,这里讲到: springboot里面还有几个日志系统框架可以选择使用,你可以通过在classpa ...
- 我的NopCommerce之旅(8): 路由分析
一.导图和基础介绍 本文主要介绍NopCommerce的路由机制,网上有一篇不错的文章,有兴趣的可以看看NopCommerce源码架构详解--对seo友好Url的路由机制实现源码分析 SEO,Sear ...
- IDEA JavaSE环境配置
需指定JDK路径: File -> Project Structure -> Project -> Project SDK -> New -> 选择JDK所在的根目录
- 【持续更新】CSS居中
水平垂直居中 知道自身的宽度.高度 <div class="test"></div> <style> .test { position: abs ...
- Mongodb JAVA API
连接mongodb 1.连接一个mongodb ); 2.连接mongodb集群 MongoClient mongoClient = ), new ServerAddress("localh ...
- Perl的Notepad++环境配置
Notepad++打开pl文件F5录入命令分别保存. Run_Perl(F9): cmd /k F:\Strawberry\perl\bin\perl.exe -w "$(FULL_CURR ...
- ES-Mac OS环境搭建-ik中文分词器
下载 从github下载ik中文分词器,点击地址,需要注意的是,ik分词器和elasticsearch版本必须一致. 安装 下载到本地并解压到elasticsearch中的plugins目录内即可. ...
- Azure 项目构建 - 用 Azure 认知服务在微信公众号上搭建智能会务系统
通过完整流程详细介绍了如何在Azure平台上快速搭建基于微信公众号的智慧云会务管理系统. 此系列的全部课程 https://school.azure.cn/curriculums/11 立即访问htt ...
- MFC技术积累——基于MFC对话框类的那些事儿3
3.3.2 创建图形画刷来实现位图加载 1.首先在Resource View中导入一幅位图,位图大小96×96像素: 2.其次在主对话框中添加一个静态文本资源,ID号是IDC_BITMAPAREA,添 ...