#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 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 people to buy one color painting.
The -th person will buy at most color paintings and at most 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 and , and this will happen times.
Customers are numbered from to .
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 .
Input Format
The first line contains two integers .
The second line contains integers .
The third line contains integers .
The fourth line contains an integer .
The next lines each contain three integers . The -th line means that customer changes and to and .
Output Format
Output lines, one integer per line. The value on the -th line represents, after the -th change, the number of valid plans .
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 of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , , , .
Notes
This problem is worth points in total.
This problem is translated from Croatian Open Competition in Informatics 2015/2016 Contest #1 T5 RELATIVNOST.
Translated by ChatGPT 5
京公网安备 11011102002149号