hdu 5480|| bestcoder   #57 div 2 Conturbatio(前缀和||树状数组)

Conturbatio

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 211    Accepted Submission(s): 99

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.

Source

BestCoder Round #57 (div.2)

比较水.

唯一一点需要注意的是...

可能有重复元素...

因为我的思路是用两棵一维树状数组搞..

每个点标记为1

然后看矩形的两个方向中是否至少有一个方向上和等于长度...

所以这样如果有重复元素的话,不处理会出错.. 

但实际上又没修改..直接前缀和就好了...

树状数组个毛线...

不过看到还有人线段树搞得233333

  1 /*************************************************************************
  2     > File Name: code/bc/#57/1002.cpp
  3     > Author: 111qqz
  4     > Email: [email protected]
  5     > Created Time: 2015年09月26日 星期六 19时31分10秒
  6  ************************************************************************/
  7
  8 #include<iostream>
  9 #include<iomanip>
 10 #include<cstdio>
 11 #include<algorithm>
 12 #include<cmath>
 13 #include<cstring>
 14 #include<string>
 15 #include<map>
 16 #include<set>
 17 #include<queue>
 18 #include<vector>
 19 #include<stack>
 20 #include<cctype>
 21 #define y1 hust111qqz
 22 #define yn hez111qqz
 23 #define j1 cute111qqz
 24 #define ms(a,x) memset(a,x,sizeof(a))
 25 #define lr dying111qqz
 26 using namespace std;
 27 #define For(i, n) for (int i=0;i<int(n);++i)
 28 typedef long long LL;
 29 typedef double DB;
 30 const int inf = 0x3f3f3f3f;
 31 const int N=1E5+7;
 32 int c[N],d[N];
 33 int n,m,K,Q;
 34 bool vx[N],vy[N];
 35
 36 int lowbit(int x)
 37 {
 38     return x&(-x);
 39 }
 40
 41 void update ( int x,int delta)
 42 {
 43     for ( int i = x ; i  <= n ; i = i + lowbit(i))
 44     {
 45     c[i] = c[i] + delta;
 46     }
 47 }
 48
 49 LL sum ( int x)
 50 {
 51     LL res = 0 ;
 52     for ( int i = x ; i >= 1 ; i = i - lowbit(i))
 53     {
 54      res  = res  + c[i];
 55     }
 56     return res;
 57 }
 58
 59 void update2( int y,int delta)
 60 {
 61     for ( int i = y ; i <= m ; i = i + lowbit(i))
 62     {
 63     d[i] = d[i] + delta;
 64     }
 65 }
 66
 67 LL sum2( int y)
 68 {
 69     LL res = 0 ;
 70     for ( int i = y  ;  i >= 1 ; i = i - lowbit(i))
 71     {
 72     res = res + d[i];
 73     }
 74     return res;
 75
 76 }
 77 int main()
 78 {
 79   #ifndef  ONLINE_JUDGE
 80    freopen("in.txt","r",stdin);
 81   #endif
 82    int T;
 83        scanf("%d",&T);
 84    while (T--)
 85     {
 86     ms(c,0);
 87     ms(d,0);
 88     memset(vx,false,sizeof(vx));
 89     memset(vy,false,sizeof(vy));
 90     scanf("%d %d %d %d",&n,&m,&K,&Q);
 91     for ( int i  = 0 ; i <K ; i++)
 92     {
 93         int x,y;
 94         scanf("%d %d",&x,&y);
 95         if (!vx[x])
 96         {
 97              update (x,1);
 98         vx [x] = true;
 99         }
100         if (!vy[y])
101         {
102         update2 (y,1);
103         vy[y] = true;
104         }
105
106     }
107     for ( int i = 0 ; i < Q ; i++)
108     {
109         int x1,y1,x2,y2;
110         scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
111         int xx = sum(x2)-sum(x1-1);
112         int yy = sum2(y2)-sum2(y1-1);
113       //  cout<<"sum(x2):"<<sum(x2)<<endl;
114       //  cout<<"sum(x1-1):"<<sum(x1-1)<<endl;
115       //  cout<<"sum(y2):"<<sum(y2)<<endl;
116       //  cout<<"sum(y1-1)"<<sum(y1-1)<<endl;
117       //  cout<<"xx:"<<xx<<endl;
118       //  cout<<"yy:"<<yy<<endl;
119         if (xx>=x2-x1+1||yy>=y2-y1+1)
120         {
121         puts("Yes");
122         }
123         else
124         {
125         puts("No");
126         }
127
128     }
129     }
130
131
132  #ifndef ONLINE_JUDGE
133   fclose(stdin);
134   #endif
135     return 0;
136 }

时间: 2024-08-23 23:27:18

hdu 5480|| bestcoder   #57 div 2 Conturbatio(前缀和||树状数组)的相关文章

HDU 6203 ping ping ping(dfs序+LCA+树状数组)

http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意: n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V 无法连通.问无法通行的点最少有多少个. 思路: 贪心思维,破坏两个点的LCA是最佳的.那么怎么判断现在在(u,v)之间的路径上有没有被破坏的点呢,如果没有的话那么此时就要破坏这个lca点.一开始我们要把询问按照u和v的lca深度从大到小排序,如果某个点需要被破坏,那么它的所有子节点都可以不再需要破坏别的点

HDU 5869 Different GCD Subarray Query (GCD种类预处理+树状数组维护)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5869 问你l~r之间的连续序列的gcd种类. 首先固定右端点,预处理gcd不同尽量靠右的位置(此时gcd种类不超过loga[i]种). 预处理gcd如下代码,感觉真的有点巧妙... 1 for(int i = 1; i <= n; ++i) { 2 int x = a[i], y = i; 3 for(int j = 0; j < ans[i - 1].size(); ++j) { 4 int g

HDU 5156 - Harry and Christmas tree (dfs序+离线树状数组)

http://acm.hdu.edu.cn/showproblem.php?pid=5156 BC#25的C题. 题意是:给出一颗大小为n的树,以1为根,然后给出m次染色,每次将节点u加上一种颜色(一个节点可以有多个颜色). 最后查询树上每个节点对应子树上包含的不同颜色数量. 当时这场比赛没有做,回来看一下题目,没看标解就试着敲了一遍,于是解题思路从一开始就走上了不归路. 标解是O(n+m)的方法,主要思路是将问题转为:一次染色表示将u到根节点的路径都染上这种颜色. 但这样做需要去重,因为如果u

【HDU】4918 Query on the subtree 点分治+树状数组

传送门:[HDU]4918 Query on the subtree 题目分析: 首先,简化问题. 1.求一次到点u的距离不超过d的点的个数.很容易,一次O(NlogN)的点分治便可以完成. 2.多次进行操作1.此时不能每次都O(NlogN)了,太慢了.我们考虑到对于点分治,树的重心一共有logN层,第一层为整棵树的重心,第二层为第一层重心的子树的重心,以此类推,每次至少分成两个大小差不多的子树,所以一共有logN层.而且,对于一个点,他最多只属于logN个子树,也就是最多只属于logN个重心.

HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 269 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 克拉克是一名人格分裂患者.某一天,有两个克拉克(aa和bb)在玩一个方格游戏. 这个方格是一个n*mn∗m的矩阵,每个格子里有一

hdu 1166 敌兵布阵——(区间和)树状数组

here:http://acm.hdu.edu.cn/showproblem.php?pid=1166 Input 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50). 接下来每行有一条命令,命令有4种形式: (1) Add i j,i和j为正整数,表示第i个营地增加j个人(j不超过30) (2)Sub i j ,i和j为正整数,表示第i

hdu 1166 敌兵布阵——(区间和)树状数组/线段树

here:http://acm.hdu.edu.cn/showproblem.php?pid=1166 Input 第一行一个整数T.表示有T组数据. 每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地.接下来有N个正整数,第i个正整数ai代表第i个工兵营地里開始时有ai个人(1<=ai<=50). 接下来每行有一条命令.命令有4种形式: (1) Add i j,i和j为正整数,表示第i个营地添加j个人(j不超过30) (2)Sub i j ,i和j为正整数,表示第i

HDU 5293 Tree chain problem 树形dp+dfs序+树状数组+LCA

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 题意: 给你一些链,每条链都有自己的价值,求不相交不重合的链能够组成的最大价值. 题解: 树形dp, 对于每条链u,v,w,我们只在lca(u,v)的顶点上处理它 让dp[i]表示以i为根的指数的最大值,sum[i]表示dp[vi]的和(vi为i的儿子们) 则i点有两种决策,一种是不选以i为lca的链,则dp[i]=sum[i]. 另一种是选一条以i为lca的链,那么有转移方程:dp[i]=

Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】

题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. The

hdu 5773 The All-purpose Zero 最长上升子序列+树状数组

题目链接:hdu 5773 The All-purpose Zero 官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的. 因此我们可以把0拿出来,对剩下的做O(nlogn)的LIS,统计结果的时候再算上0的数量. 为了保证严格递增,我们可以将每个权值S[i]减去i前面0的个数,再做LIS,就能保证结果是严格递增的. 个人看法:对于显然把所以0放进去部分我解释一下: 如果0位于最长上升子序列两边,这两个零要加进去是显然的 如果有一个0夹于最长上升子序列之间,那么