1266 - Points in Rectangle
Time Limit: 2 second(s) Memory Limit: 32 MB

As the name says, this problem is about finding the number of points in a rectangle whose sides are parallel to axis. All the points and rectangles consist of 2D Cartesian co-ordinates. A point that lies in the boundary of a rectangle is considered inside.

Input

Input starts with an integer T (≤ 10), denoting the number of test cases.

Each case starts with a line containing an integer q (1 ≤ q ≤ 30000) denoting the number of queries. Each query is either one of the following:

1)      0 x y, meaning that you have got a new point whose co-ordinate is (x, y). But the restriction is that, if a point (x, y) is already listed, then this query has no effect.

2)      1 x1 y1 x2 y2 meaning that you are given a rectangle whose lower left co-ordinate is (x1, y1) and upper-right corner is (x2, y2); your task is to find the number of points, given so far, that lie inside this rectangle. You can assume that (x1 < x2, y1 < y2).

You can assume that the values of the co-ordinates lie between 0 and 1000 (inclusive).

Output

For each case, print the case number in a line first. Then for each query type (2), you have to answer the number of points that lie inside that rectangle. Print each of the results in separated lines.

Sample Input

Output for Sample Input

1

9

0 1 1

0 2 6

1 1 1 6 6

1 2 2 5 5

0 5 5

1 0 0 6 5

0 3 3

0 2 6

1 2 1 10 10

Case 1:

2

0

2

3

Note

Dataset is huge, use faster I/O methods.


PROBLEM SETTER: JANE ALAM JAN
思路:二维树状数组;
模板题:
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<stdlib.h>
5 #include<queue>
6 #include<string.h>
7 using namespace std;
8 int bit[1005][1005];
9 bool flag[1005][1005];
10 int lowbit(int x)
11 {
12 return x&(-x);
13 }
14 void add(int x1,int y1)
15 {
16 int i,j;
17 for(i = x1; i <= 1001; i+=lowbit(i))
18 for(j = y1; j <= 1001; j+=lowbit(j))
19 {
20 bit[i][j]++;
21 }
22 }
23 int ask(int x1,int y1)
24 {
25 int i,j;
26 int sum = 0;
27 for(i = x1; i > 0; i-=lowbit(i))
28 for(j = y1; j > 0; j-=lowbit(j))
29 {
30 sum+=bit[i][j];
31 }
32 return sum;
33 }
34 int main(void)
35 {
36 int T;
37 scanf("%d",&T);
38 int __ca = 0,q;
39 while(T--)
40 {
41 __ca++;
42 memset(bit,0,sizeof(bit));
43 memset(flag,0,sizeof(flag));
44 scanf("%d",&q);
45 printf("Case %d:\n",__ca);
46 int val ;
47 int x,y,x1,y1;
48 while(q--)
49 {
50 scanf("%d",&val);
51 if(!val)
52 {
53 scanf("%d %d",&x,&y);
54 x+=1;
55 y+=1;
56 if(!flag[x][y])
57 {
58 add(x,y);
59 flag[x][y]=true;
60 }
61 }
62 else
63 {
64 scanf("%d %d %d %d",&x,&y,&x1,&y1);
65 x++;y++;x1++;y1++;
66 int sum = ask(x1,y1);
67 sum += ask(x-1,y-1);
68 sum -= ask(x-1,y1);
69 sum -= ask(x1,y-1);
70 printf("%d\n",sum);
71 }
72 }
73 }
74 return 0;
75 }
76

复杂度:n*log(n)^2;

1266 - Points in Rectangle的更多相关文章

  1. Light OJ 1266 - Points in Rectangle

    题目 Link 就是查询矩形内有多少个点. 分析 二维树状数组维护就好了,. Code #include <bits/stdc++.h> const int maxn = 1000 + 1 ...

  2. D. Points in rectangle

    D. Points in rectangle 单点时限: 2.0 sec 内存限制: 512 MB 在二维平面中有一个矩形,它的四个坐标点分别为(0,a),(a,0),(n,n−a),(n−a,n). ...

  3. C++ 基于凸包的Delaunay三角网生成算法

    Delaunay三角网,写了用半天,调试BUG用了2天……醉了. 基本思路比较简单,但效率并不是很快. 1. 先生成一个凸包: 2. 只考虑凸包上的点,将凸包环切,生成一个三角网,暂时不考虑Delau ...

  4. 人脸识别引擎SeetaFaceEngine中Alignment模块使用的测试代码

    人脸识别引擎SeetaFaceEngine中Alignment模块用于检测人脸关键点,包括5个点,两个眼的中心.鼻尖.两个嘴角,以下是测试代码: int test_alignment() { std: ...

  5. Opencv 最小外接矩形合并拼接

    前一篇画出了最小外接矩形,但是有时候画出来的矩形由于中间像素干扰或者是其他原因矩形框并不是真正想要的 如图1是一个信号的雨图,被矩形框分割成了多个小框: 需要合并矩形框达到的效果: 主要思想: 扫描两 ...

  6. HPU暑期集训积分赛2

    A. 再战斐波那契 单点时限: 1.0 sec 内存限制: 512 MB 小z 学会了斐波那契和 gcd 后,老师又给他出了个难题,求第N个和第M个斐波那契数的最大公约数,这可难倒了小z ,不过在小z ...

  7. pdf 中内容的坐标系

    PDF Page Coordinates (page size, field placement, etc.) AcroForm, Basics, Automation Page coordinate ...

  8. leetcode 1266. Minimum Time Visiting All Points

    On a plane there are n points with integer coordinates points[i] = [xi, yi]. Your task is to find th ...

  9. 【leetcode】1266. Minimum Time Visiting All Points

    题目如下: On a plane there are n points with integer coordinates points[i] = [xi, yi]. Your task is to f ...

随机推荐

  1. PhantomJS的安装和使用

    PhantomJS是一个无界面的.可脚本编程的WebKit浏览器引擎,它原生支持多种Web标准:DOM操作.CSS选择器.JSON.Canvas以及SVG.Selenium支持PhantomJS,这样 ...

  2. 8种Vue中数据更新了但页面没有更新的情况

    目录 1.Vue 无法检测实例被创建时不存在于 data 中的 属性 2. Vue 无法检测'对象属性'的添加或移除 3.Vue 不能检测利用数组索引直接修改一个数组项 4.Vue 不能监测直接修改数 ...

  3. 【模板】二分图最大权完美匹配(KM算法)/洛谷P6577

    题目链接 https://www.luogu.com.cn/problem/P6577 题目大意 给定一个二分图,其左右点的个数各为 \(n\),带权边数为 \(m\),保证存在完美匹配. 求一种完美 ...

  4. Hadoop入门 集群崩溃的处理方法

    目录 集群崩溃的处理方法 搞崩集群 错误示范 正确处理方法 1 回到hadoop的家目录 2 杀死进程 3 删除每个集群的data和logs 4 格式化 5 启动集群 总结 原因分析 集群崩溃的处理方 ...

  5. Ganglia 简单介绍与安装

    文章来至于   http://sachinsharm.wordpress.com/2013/08/17/setup-and-configure-ganglia-3-6-on-centosrhel-6- ...

  6. Https原理及证书管理

    Https原理及证书管理 SSL(Secure Sockets Layer,安全套接层)/TLS(Transport Layer Security,传输层安全)保证了客户端web服务器的连接安全.客户 ...

  7. 【Linux】【Basis】【网络】网络相关的内核参数

    Linux系统内核设置优化tcp网络,# vi /etc/sysctl.conf,添加以下内容 net.ipv4.tcp_syncookies = 1 表示开启SYN Cookies.当出现SYN等待 ...

  8. Playing with Destructors in C++

    Predict the output of the below code snippet. 1 #include <iostream> 2 using namespace std; 3 4 ...

  9. 阿里云发布CloudOps白皮书,ECS自动化运维套件新升级

    12月10 日,2021云上架构与运维峰会上,阿里云发布业界首部<云上自动化运维白皮书>(简称CloudOps白皮书),并在其中提出了CloudOps成熟度模型.同时,阿里云还宣布了ECS ...

  10. 网络访问控制列表ACL(读懂这篇就基本够了,后面有配置案例)

    一.访问控制列表是什么? 访问控制列表(ACL)是一种基于包过滤的访问控制技术,它可以根据设定的条件对接口上的数据包进行过滤,允许其通过或丢弃.访问控制列表被广泛地应用于路由器和三层交换机,借助于访问 ...