#P5874. [IOI 2015] horses

[IOI 2015] horses

Description

Like his ancestors, Mansur enjoys breeding horses. He currently owns the largest horse ranch in Kazakhstan. It was not always like this: NN years ago, when Mansur was young, he only owned one horse, but he kept dreaming of becoming rich, and in the end his dream came true.

Number the years in chronological order from 00 to N1N-1 (that is, year N1N-1 is the most recent year). Each year’s weather affects horse breeding. Mansur records a positive integer X[i]X[i] as the breeding factor of year ii. If there are hh horses at the beginning of year ii, then there will be h×X[i]h \times X[i] horses at the end of that year.

Each year, horses can only be sold at the end of the year. Mansur records a positive integer Y[i]Y[i] as the price for selling one horse at the end of year ii. Mansur may sell any number of horses, and each horse is sold for Y[i]Y[i].

Now, Mansur wants to know: over these NN years, if he always sells horses at the best time, what is the maximum total revenue he can obtain? You happen to be visiting Mansur’s home, so he asks you to help answer this question.

Mansur performed MM updates to the recorded arrays XX and YY. In each update, Mansur either changes one X[i]X[i] or changes one Y[i]Y[i]. After each update, he asks you again for the maximum revenue from selling horses. Mansur’s updates are cumulative, meaning each answer should take into account all previous updates. Note that some X[i]X[i] or Y[i]Y[i] may be updated multiple times.

The real answer to Mansur’s question may be extremely large. You only need to output the real answer modulo 109+710^9+7.

Input Format

  • Line 11: An integer NN, the total number of years.
  • Line 22: NN positive integers X[0],,X[N1]X[0],\cdots,X[N - 1]. For 0iN10\le i \le N-1, X[i]X[i] is the breeding factor of year ii.
  • Line 33: NN positive integers Y[0],,Y[N1]Y[0],\cdots,Y[N - 1]. For 0iN10\le i \le N-1, Y[i]Y[i] is the price of selling one horse at the end of year ii.
  • Line 44: An integer MM, the number of updates.
  • Lines 55 to M+4M+4: Each line contains three numbers typetype, pospos, valval (type=1type=1 means changing X[pos]X[ pos ] to valval, type=2type=2 means changing Y[pos]Y[ pos ] to valval).

Output Format

  • A total of M+1M+1 lines.
  • Line 11: One integer, the maximum revenue in the initial state modulo 109+710^9+7.
  • Lines 22 to M+1M+1: One integer per line, the maximum revenue after this update modulo 109+710^9+7.
3
2 1 3
3 4 1
1
2 1 2

8
6

Hint

Constraints: for 100%100\% of the data, 1N5×1051\le N\le 5\times 10^5, 0M1050 \le M \le 10^5.

Translated by ChatGPT 5