|
||||||||||
Hun Gui Wei CompanyTime Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 604 Accepted Submission(s): 158 Problem Description My friend Hun Gui Wei (HGW) has started a company which is named Hun Gui Wei Company (HGWC). In HGWC, there are many staffs. Every staff has a certain salary, level and working age. Sometimes, HGW wants to do some queries. He wants to know the sum of salary of the staffs fit some conditions. For the large amount of staffs, artificial query is time-consuming. So he wants to hire you to write a program to help him. If you do a good job, he will pay you a generous remuneration. Input Multi test cases (about 10). The first line contains an integer n indicates there are n staffs in HGWC. In the next n lines, each line describes the attributes of one staff. Each line contains S, L, A indicate the salary, level and working age of one staff. Next line an integer m comes which indicates there will be m queries. Then next m lines, query dates will come $\begin{matrix} LL_0 & HL_0 & LA_0 & HA_0 \\ LL_1 & HL_1 & LA_1 & HA_1 \\ \vdots & \vdots & \vdots & \vdots \\ LL_{m-1} & HL_{m-1} & LA_{m-1} & HA_{m-1} \end{matrix}$ HGW sets a variable k. In the beginning of each test case, k = 0. For the i-th query, he sets $LL_i = LL_i + k, HL_i = HL_i - k, LA_i = LA_i + k, HA_i = HA_i - k$, then make k the answer of this query. [Technical Specification] All numbers in the input are integers. $1 \leq n, m \leq 10^5$ $0 \leq S, L, A \leq 10^9$ $-10^{17} \leq LL_i, HL_i, LA_i, HA_i \leq 10^{17}$ Output For i-th query£Ĵoutput the sum of salary of the staffs whose level are between $LL_i$ and $HL_i$ while working age are between $LA_i$ and $HA_i$ in a single line. Sample Input
Sample Output
Hint For this case, first we clear k i.e. set k to 0. For the first query we should find the staff whose level is between 2 and 3 while working age is exactly 3. There is only one staff fitting the conditions whose salary is 1. So the answer for the first query is 1. Then we set k to 1. For the second query we should update query parameters according to the statement. Thus after updating, the query parameters become 3 5 3 6. There is also only one staff fitting the condition whose salary is 4. So the answer for the second case is 4. Source | ||||||||||
|