#P6533. [COCI 2015/2016 #1] RELATIVNOST

[COCI 2015/2016 #1] RELATIVNOST

Description

You are a master of counting. One day, your friend Luka came up with a problem to challenge you.

Luka is a hardworking painter. His paintings are so good that there will be nn people who want to buy his paintings.

There are two types of paintings: black-and-white paintings and color paintings.

Luka is very hardworking, so he has infinitely many paintings.

Luka hates selling black-and-white paintings, so he wants at least cc people to buy one color painting.

The ii-th person will buy at most aia_i color paintings and at most bib_i black-and-white paintings, and they will buy at least one painting.

However, each customer can only buy either color paintings or black-and-white paintings.

Customers keep changing aia_i and bib_i, and this will happen qq times.

Customers are numbered from 11 to nn.

You need to find, after each change, how many plans Luka has that satisfy all requirements.

To prevent the output from being too large, Luka only needs you to output the number of plans mod 104+7\bmod\ 10^4+7.

Input Format

The first line contains two integers n,cn,c.

The second line contains nn integers aia_i.

The third line contains nn integers bib_i.

The fourth line contains an integer qq.

The next qq lines each contain three integers pi,api,bpip_i,a_{p_i},b_{p_i}. The ii-th line means that customer pip_i changes aia_i and bib_i to apia_{p_i} and bpib_{p_i}.

Output Format

Output qq lines, one integer per line. The value on the ii-th line represents, after the ii-th change, the number of valid plans mod 104+7\bmod\ 10^4+7.

2 2
1 1
1 1
1
1 1 1 

1
2 2
1 2
2 3
2
1 2 2
2 2 2
4
4
4 2
1 2 3 4
1 2 3 4
1
4 1 1

66

Hint

Sample 1 Explanation

After the first change, we have only one valid plan: sell one color painting to each of the two customers.

Constraints and Limits

  • For 30%30\% of the testdata, it is guaranteed that n,q103n,q\le 10^3.
  • For 100%100\% of the testdata, it is guaranteed that 1n,q1051\le n,q\le 10^5, 1c201\le c\le 20, 1ai,bi,api,bpi1091\le a_i,b_i,a_{p_i},b_{p_i}\le 10^9, 1pin1\le p_i\le n.

Notes

This problem is worth 140140 points in total.

This problem is translated from Croatian Open Competition in Informatics 2015/2016 Contest #1 T5 RELATIVNOST.

Translated by ChatGPT 5