编程介的小学生 2017-08-22 12:28 采纳率: 20.5%
浏览 732
已采纳

Population

It is always exciting to see people settling in a new continent. As the head of the population management office, you are supposed to know, at any time, how people are distributed in this continent.

The continent is divided into square regions, each has a center with integer coordinates (x, y). Hence all the people coming into that region are considered to be settled at the center position. Given the positions of the corners of a rectangle region, you are supposed to count the number of people living in that region.

Input

Your program must read inputs from the standard input. Since there are up to 32768 different regions and possibly even more queries, please use "scanf" and "printf" instead of "cin" and "cout" to avoid timeout.

The character "I" in a line signals the coming in of new groups of people. In the following lines, each line contains three integers: X, Y, and N, where X and Y (1 <= X, Y <= 20000) are the coordinates of the region's center, and N (1 <= N <= 10000) is the number of people coming in.

The character "Q" in a line signals the query of population. The following lines each contains four numbers: Xmin, Xmax, Ymin, Ymax, where (Xmin, Ymin) and (Xmax, Ymax) are the integer coordinates of the lower left corner and the upper right corner of the rectangle, respectively.

The character "E" signals the end of a test case. Process to the end of file.

Output

For each "Q" case, print to the standard output in a line the population in the given rectangle region. That is, you are supposed to count the number of people living at all the positions (x, y) such that Xmin <= x <= Xmax, and Ymin <= y <= Ymax.

Sample Input

I
8 20 1
4 5 1
10 11 1
12 10 1
18 14 1
Q
8 10 5 15
8 20 10 14
I
7 6 1
10 3 2
7 2 1
2 3 2
10 3 1
Q
2 20 2 20
E
Sample Output

1
3
12

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-08-27 15:15
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集