luogu#P4891. 序列

序列

Background

The testdata for this problem has been updated.

Problem Description

Given two sequences AA and BB of length nn, define the sequence Ci=maxj=1iAjC_i=\max\limits_{j=1}^i A_j.

Define the current value as i=1nmin(Bi,Ci)\prod\limits_{i=1}^n \min(B_i,C_i).

Now there are qq operations. Each operation modifies one position in sequence AA or BB, and the number will increase. You need to output the value after each modification.

Input Format

The first line contains two integers n,qn,q.

The second line contains nn integers representing AiA_i.

The third line contains nn integers representing BiB_i.

The next qq lines each contain three integers opt,x,yopt,x,y. If opt=0opt=0, it means an operation on sequence AA; if opt=1opt=1, it means an operation on sequence BB. Set the xx-th element of the corresponding sequence to yy. It is guaranteed that yy is not smaller than the original element.

Output Format

Output qq lines, each being the value after the corresponding modification.

Since the answer can be very large, output it modulo 109+710^9+7.

3 1
2 1 3
1 2 3
1 3 5

6

Hint

For all testdata, 1n,q105,0Ai,Bi,y1091 \le n,q\le 10^5,0\le A_i,B_i,y \le 10^9.

For 20% of the Constraints, 1n,q10001\le n,q\le 1000.

For another 10% of the Constraints, opt=1opt=1.

For another 20% of the Constraints, opt=0opt=0.

For 80% of the Constraints, n,q50000n,q\le 50000.

Translated by ChatGPT 5