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出状态值之后需要标记,遍历肯定会超时,这就需要使用树状数组,二维的树状数组,和一维用法一样。在使用树状数组的时候要注意一下边界的问题


  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 3000;
  4. const int _hash = 233;
  5. typedef long long ll;
  6. ll maps[maxn][maxn];
  7. ll n,m,q;
  8. ll lowbit(ll x)
  9. {
  10. return x&-x;
  11. }
  12. void updata(ll x,ll y,ll val)
  13. {
  14. for(ll i=x; i<=n; i+=lowbit(i))
  15. for(ll j=y; j<=m; j+=lowbit(j))
  16. maps[i][j] += val;
  17. }
  18. void updata(ll x1,ll y1,ll x2,ll y2,ll val)
  19. {
  20. //需要注意一下边界的问题
  21. updata(x1,y1,val);
  22. updata(x1,y2+1,-val);
  23. updata(x2+1,y1,-val);
  24. updata(x2+1,y2+1,val);
  25. }
  26. ll query(ll x,ll y)
  27. {
  28. ll ans = 0;
  29. for(ll i=x;i;i-=lowbit(i))
  30. for(ll j=y;j;j-=lowbit(j))
  31. ans += maps[i][j];
  32. return ans;
  33. }
  34. void query(ll x1,ll y1,ll x2,ll y2)
  35. {
  36. ll ans1,ans2;
  37. ans1 = ans2 = 0;
  38. ans1 = query(x1,y1);
  39. ans2 = query(x2,y2);
  40. if(ans1 == ans2)
  41. printf("Yes\n");
  42. else
  43. printf("No\n");
  44. }
  45. int main()
  46. {
  47. scanf("%lld%lld%lld",&n,&m,&q);
  48. while(q--)
  49. {
  50. ll mark,x1,x2,y1,y2;
  51. scanf("%lld%lld%lld%lld%lld",&mark,&x1,&y1,&x2,&y2);
  52. ll temp = 1;
  53. //hash
  54. temp = temp*_hash + x1;
  55. temp = temp*_hash + x2;
  56. temp = temp*_hash + y1;
  57. temp = temp*_hash + y2;
  58. if(mark == 2)//拆除状态是建立状态的倒数
  59. temp = -temp;
  60. else if(mark == 3)
  61. {
  62. query(x1,y1,x2,y2);
  63. continue;
  64. }
  65. updata(x1,y1,x2,y2,temp);
  66. }
  67. }

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. centos安装openldap过程

    1.下载软件如下,db是数据库 2.首先安装数据库db # tar xf db-4.8.30.tar.gz # cd db-4.8.30 # cd build_unix/ (# ../dist/con ...

  2. 头部和信号栏一个颜色appcloud

    <header id="header" > <ul > <li class="active" onclick="api. ...

  3. handler 方法进不去,服务器上出现应用程序错误。此应用程序的当前自定义错误设置禁止远程查看

    HTTP/1.1 500 Internal Server ErrorCache-Control: privateContent-Type: text/html; charset=utf-8Server ...

  4. h5旋转效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. Java静态方法不能被覆盖

    // 静态方法不能被覆盖   /*class Super{     static String name(){         return "mother";     } }   ...

  6. Azure 项目构建 – 托管静态网站

    本课程主要介绍了如何在 Azure 平台上快速构建和部署基于 Azure Web 应用的静态托管网站, 实践讲解如何使用 Azure 门户创建 Web 应用, 部署静态网站源代码,设置自定义域名等. ...

  7. [习题]输入自己的生日(年/月/日)#2 -- 日历(Calendar)控件的时光跳跃,一次跳回五年、十年前?--TodaysDate属性、VisibleDate属性

    原文出處  http://www.dotblogs.com.tw/mis2000lab/archive/2013/06/10/calendar_visibledate_birthday_dropdow ...

  8. Kubernetes里的ConfigMap的用途

    顾名思义,ConfigMap用于保存配置数据的键值对,可以用来保存单个属性,也可以用来保存配置文件. ConfigMap同Kubernetes的另一个概念secret类似,区别是ConfigMap主要 ...

  9. 关键字: on

    关键字: on 数据库在通过连接两张或多张表来返回记录时,都会生成一张中间的临时表,然后再将这张临时表返回给用户. 在使用left jion时,on和where条件的区别如下: 1. on条件是在生成 ...

  10. 动态规划初步--最长上升子序列(LIS)

    一.问题 有一个长为n的数列 a0,a1,a2...,an-1a.请求出这个序列中最长的上升子序列的长度和对应的子序列.上升子序列指的是对任意的i < j都满足ai < aj的子序列. 二 ...