#P3755. [CQOI2017] 老C的任务

    ID: 1341 远端评测题 1000~3000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2017重庆各省省选离散化主席树前缀和

[CQOI2017] 老C的任务

Description

Old C is a programmer.

Recently, Old C received a task from his boss — to write a management system for mobile base stations in the city. As an experienced programmer, Old C easily completed most of the system and left one feature for you to implement.

Since the area covered by one base station is very small compared to the whole city, each base station can be regarded as a point in the coordinate plane, with its position represented by coordinates (x,y)(x,y). In addition, each base station has many attributes, such as height and power. The operator often specifies a region and queries the information of all base stations in that region.

Your task is: for a given rectangular region, answer the sum of the power values of all base stations inside the region (including those on the boundary). If the region contains no base stations, output 00.

Input Format

The first line contains two integers n,mn,m, meaning there are nn base stations and mm queries. The next nn lines each contain three space-separated integers xi,yi,pix_i,y_i,p_i, representing a base station at coordinates (xi,yi)(x_i,y_i) with power pip_i. No two base stations share the same coordinates.

Then follow mm lines, each containing four space-separated integers x1,y1,x2,y2x_1,y_1,x_2,y_2, denoting one query rectangle. The rectangle has diagonally opposite corners at (x1,y1)(x_1,y_1) and (x2,y2)(x_2,y_2), and its sides are parallel to the coordinate axes.

Output Format

Output mm lines, each containing one integer, the answer for the corresponding query.

4 2   
0 0 1 
0 1 2  
2 2 4  
1 0 8  
0 0 1 1 
1 1 5 6 
11
4
3 2
-100 0 16 
1 -10 32 
1000 100 64 
0 0 0 1 
-1000 -1000 10000 10000 
0
112

Hint

For testdata 121 \sim 2, 1n,m1001 \le n,m \le 100.

For testdata 353 \sim 5, 1n500001 \le n \le 50000, 1m100001 \le m \le 10000.

For testdata 6106 \sim 10, 1n1000001 \le n \le 100000, 1m1000001 \le m \le 100000, and the testdata has a gradient.

For all testdata, 231xi,yi,pi,x1,y1,x2,y2<231-2^{31} \le x_i,y_i,p_i,x_1,y_1,x_2,y_2 < 2^{31}, x1x2x_1 \le x_2, y1y2y_1 \le y_2.

Translated by ChatGPT 5