Selling horses
Time limit2sMemory limit512 MB
One horse multiplies by X[i] each year and any held horses sell at price Y[i]; report the maximum revenue after each point update modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Segment tree, Greedy, Math
- Solved
- No attempts yet
Problem
Mansur raises horses. Today he owns more horses than anyone else in Kazakhstan, but years ago he was a young man with a single horse.
Number the years from 0 to in chronological order, so year is the most recent one. The weather in year decides how fast the herd grows, and the growth rate is a positive integer . If Mansur has horses at the start of year , he has horses at the end of that year.
Horses are sold only at the end of a year. At the end of year one horse sells for a positive integer , and there is no limit on how many of the horses he holds at that moment he sells.
Mansur wants to know how much money he could have made over the last years if he had picked the selling times perfectly. Through the evening his memory sharpens, so he corrects the numbers times. Each correction replaces one or one with a new value, and the corrections pile up. The same position is corrected more than once in some cases.
Compute the largest amount of money he could make with the initial numbers, and the largest amount after each correction. The answer gets very large, so print it modulo .
Input
The first line contains the number of years .
The second line contains integers to , separated by spaces.
The third line contains integers to , separated by spaces.
The fourth line contains the number of corrections .
Each of the next lines contains one correction in the form type pos val. If type is 1, then becomes val. If type is 2, then becomes val.
Limits:
- and , both for the initial values and after every correction
typeis 1 or 2, , and
Output
Print lines.
The first line holds the largest amount of money Mansur could make with the initial numbers. The -th line after that holds the largest amount once the first corrections have all been applied.
Every value is printed modulo .