## DMOPC '14 Contest 2 P6 - Selective Cutting

View as PDF

Points: 12 (partial)
Time limit: 0.25s
Java 1.0s
Python 1.0s
Memory limit: 128M

Authors:
Problem type

The Logging Company has been hit with a petition from concerned citizens regarding their uncontrolled tree-cutting. For public relations purposes, they have decided that, moving forward, they will only cut down trees with mass above a certain threshold.

The Logging Company has a line of trees. Each tree has a mass . The Company wants to cut some of the trees, so they've hired you to calculate the mass of all the wood they would get from cutting all the trees with greater than or equal to between positions and inclusive . In particular, they want you to answer such queries.

#### Input Specification

The first line will contain the integer . For each tree , the (from 0) integer on the second line will contain the integer mass . The third line will contain the number , the number of queries the logging company wants you to answer. The next lines will contain three integers and and .

#### Output Specification

For each query, print the total mass of the trees at position such that , and .

#### Sample Input

5
1 3 4 2 5
5
0 4 3
1 3 2
0 4 5
4 4 1
0 4 1

#### Sample Output

12
9
5
5
15

• commented on July 19, 2017, 9:26 p.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on March 28, 2015, 4:14 a.m.

My solution doesn't work for the 3rd batch test case, can anyone give me a hint why?

• commented on March 28, 2015, 4:03 p.m.

2 mistakes in your code: 1) "ans" in your query structure is int, not long long. It will overflow. 2) x=max(x,q) is not right, since some mass is much larger than the query. Your solution ignores all masses which are bigger than the largest query. So, x in your code should be the largest of all a and all q. Fix these mistakes, you'll AC.

• commented on March 27, 2015, 3:07 a.m.

Can anyone share an algorithm that doesn't involve iterating through all trees from a - b?

• commented on March 27, 2015, 3:12 a.m. edited

I would, but if I did fatal would get mad at me for violating TOS and stuff.

Edit: Xyene is nice.

• commented on March 27, 2015, 3:16 a.m.

Ah. sorry. I wasn't aware. I'm more interested in the learning aspect than the points system. I've see what you mean in the TOS.

• commented on March 27, 2015, 3:17 a.m. edit 2

Learning is fine. However, the comments section is not the appropriate place to discuss this topic -- we have editorials for this particular problem at https://dmoj.ca/problem/dmopc14c2p6/editorial.

• commented on March 27, 2015, 3:18 a.m.

I see, thanks.