ADATAXES - Ada and Taxes
As you might already know, Ada the Ladybug is a farmer. She grows vegetables in a long furrow. All of the vegetables have some height. Local politicians tax small vegetables, but as the furrow is very long, they always tax just a part of it.
The taxes always have some limit on height. They are calculated very simply: Tax collectors multiply the heights of all vegetables, which are lesser or equal to limit and are on desired segment.
The taxes might be very high so tax collectors just round their income and take only 1000000007 (109+7) banknotes. They are very kind, so they always leave the rest to Ada. She is interested in how much they will leave her.
NOTE: If none of the vegeteble is lesser/equal to given limit, Ada is left with symbolical 1 "money".
The first line contains an integer 1 ≤ N, Q ≤ 3*105, the number of vegetables Ada grows and the number of times the tax collectors come.
The second line contains N integers 1 ≤ Ai ≤ 3*105, the heights of vegetables.
The next Q lines contains three integers 0 ≤ L ≤ R < N, the left and right vegetables of segment and 1≤ H ≤ 3*105, the limit.
OutputPrint a single line for each query with the number of money Ada will be left with after each tax collecting.
10 6 1 2 3 4 5 10 9 8 7 6 5 5 5 0 2 3 0 9 9 4 8 8 2 4 11 2 2 3
1 6 362880 280 60 3
What was number theory in this?
cin,cout costed me extra two WA finally solved
Woah! Getting TLE with O(NlogN + QlogQ + Q√A) approach. Should try with segment tree, I guess.
Last edit: 2017-07-21 11:45:16
@[Rampage] Blue.Mary: Sorry, seems I deleted part of input instead of harsh warning :'( is it better now? :O
The input specification doesn't match the sample input.