MWC '15 #7 P2: Thief in the Night

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

There exists an apartment building with F (1F5) floors and R (1R10000) apartments per floor. All the neighbours coexist with each other peacefully and enjoy life in the city. However, these are not safe times. aurpine has been breaking into various apartments and stealing white noise CDs from the tenants!

aurpine knows that each apartment has Ci (1Ci100) CDs, and wants to listen to as many white noise CDs as possible. To do so, he asks you to determine the total amount of white noise CDs he can get by robbing all apartments between apartment a and apartment b (1abR) (inclusive) on floor c (1cF). As he is very thorough, he will ask you Q (1Q500000) questions in total.

Input Specification

On the first line, two space separated integers F and R.

The next F lines contain R integers representing Ci, the number of CDs in the ith apartment.

On the next line, one integer Q, representing the number of questions.

The next Q lines each contain three integers a, b and c.

Note: For 40% of points, 1R1000 and 1Q20.

Output Specification

Output Q lines each containing one integer, representing the total amount of white noise CDs aurpine can get by robbing all apartments between apartment a and b on floor c.

Sample Input

Copy
2 5
1 2 3 4 5
5 6 4 3 6
3
1 3 1
2 5 2
3 4 1

Sample Output

Copy
6
19
7

Explanation of Sample Output

The total white noise CDs contained in apartments 1 to 3 on floor 1 is 1+2+3=6.

The total white noise CDs contained in apartments 2 to 5 on floor 2 is 6+4+3+6=19.

The total white noise CDs contained in apartments 3 to 4 on floor 1 is 3+4=7.


Comments


  • 4
    println_hi_  commented on Nov. 3, 2016, 10:52 a.m.

    Fast I/O needed