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的更多相关文章

  1. Codeforces Round #439 (Div. 2)【A、B、C、E】

    Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...

  2. 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 ...

  3. Codeforces Round #439 (Div. 2) 题解

    题目链接  Round 439 div2 就做了两道题TAT 开场看C题就不会 然后想了好久才想到. 三种颜色挑出两种算方案数其实是独立的,于是就可以乘起来了. E题想了一会有了思路,然后YY出了一种 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  7. Codeforces Round #439 (Div. 2)

    A. The Artful Expedient 题目链接:http://codeforces.com/contest/869/problem/A 题目意思:给你两个数列,各包含n个数,现在让你从上下两 ...

  8. 「日常训练」The Intriguing Obsession(CodeForces Round #439 Div.2 C)

    2018年11月30日更新,补充了一些思考. 题意(CodeForces 869C) 三堆点,每堆一种颜色:连接的要求是同色不能相邻或距离必须至少3.问对整个图有几种连接方法,对一个数取模. 解析 要 ...

  9. Codeforces Round #439 (Div. 2) C. The Intriguing Obsession

    C. The Intriguing Obsession 题目链接http://codeforces.com/contest/869/problem/C 解题心得:     1.由于题目中限制了两个相同 ...

随机推荐

  1. 使用CSS 实现菱形图片,斜条纹背景

    比较简单的菱形图片: 效果如下 代码部分: <div class="d1"> <img src="img/5.jpg"> </di ...

  2. 一、使用MyBatis

    定义sql映射xml文件 userMapper.xml文件的内容如下: <!--头文件--> <!DOCTYPE mapper PUBLIC "-//mybatis.org ...

  3. vuex2 10分钟快速入门

    因为太简单了,我直接就贴代码了~ #建立store.js import Vue from 'vue'; import Vuex from 'vuex'; Vue.use(Vuex) export de ...

  4. Tame Your Software Dependencies for More Flexible Apps

    http://msdn.microsoft.com/en-us/magazine/cc337885.aspx

  5. 洛谷 P1902 刺杀大使

    刺杀大使 一道并不难的二分题,竟让我交了上20次,诶,果然还是我太弱了. 看完题目就基本想到要怎么做了: 只需要对最小伤害代价进行二分即可,check()函数里用搜索判断是否可以到达最后一行,这里的c ...

  6. Spring下读取properties文件

    由于在spring的xml文件中配置了 <bean id="validator" class="org.springframework.validation.bea ...

  7. Linux的安装与配置

    PS:本文适合刚刚了解Linux系统,并想要学习Linux系统的一些基本操作的同学.只要按如下方法安装配置好,就可以在自己的电脑上使用Linux系统了. 一.安装前的准备 1.下载并安装VMware ...

  8. OPENFIRE 启动流程

    在java>org>jivesoftware>openfire>starter,该类中的main方法启动,有图为证: 在start中方法分别调用unpackArchives和f ...

  9. ZOJ 3627 Treasure Hunt II (贪心,模拟)

    题意:有n个城市并排着,每个城市有些珠宝,有两个人站在第s个城市准备收集珠宝,两人可以各自行动,但两人之间的距离不能超过dis,而且每经过一个城市就需要消耗1天,他们仅有t天时间收集珠宝,问最多能收集 ...

  10. POJ 1655 Balancing Act (树的重心,常规)

    题意:求树的重心,若有多个重心,则输出编号较小者,及其子树中节点最多的数量. 思路: 树的重心:指的是一个点v,在删除点v后,其子树的节点数分别为:u1,u2....,设max(u)为其中的最大值,点 ...