#P5455. [THUPC 2018] 弗雷兹的玩具商店
[THUPC 2018] 弗雷兹的玩具商店
Description
Freyz has a toy store in City C. The store sells kinds of toys, numbered . The unit price of toy is yuan, and buying one unit of this toy provides happiness value .
One day, children came to City C. According to reliable information, these children will come to the store together at certain times to buy things. Each time, the -th child will bring exactly yuan ().
Because some toys are especially good, every time the children will only choose toys within a specific index range.
Also, since the children were already so happy in last year’s Tsinghua programming contest that they could not stop, Freyz gave up treating them, so the children can buy toys without limits. That is, for any toy, each child can buy any non-negative integer quantity each time.
As time moves forward quickly, the popularity and prices of toys may also change.
To help you handle this information, Yazid organized it and found that there were events in Freyz’s toy store during these days.
Each event has basic parameters . Here is an integer from to , representing the type of the event:
-
For an event with , Yazid will also give you an extra parameter , meaning this is a price adjustment event: increase the unit price of all toys with indices in by yuan. To prevent a unit price from exceeding yuan and making the toy never purchasable by the children, Freyz will subtract from any unit price that exceeds . (It is guaranteed that is a positive integer not exceeding .)
-
For an event with , Yazid will also give you an extra parameter , meaning this is a happiness modification event: increase the happiness value of all toys with indices in by . (Note that may be negative.)
-
For an event with , this is a purchase event: all children come to Freyz’s toy store and buy freely among the toys with indices in .
Now, for each purchase event, you want to know:
-
The sum of the maximum total happiness that all children can obtain.
-
The xor sum of the maximum total happiness that all children can obtain (xor is the operation, i.e. the
^operator in C++/Java/Python).
Input Format
-
Line : two positive integers , representing the number of toys and the number of children.
-
Line : positive integers , describing the unit price of each toy.
-
Line : positive integers , describing the happiness value of each toy.
-
Line : one non-negative integer , representing the number of events.
-
The next lines describe all events, one per line. Each line starts with three integers , as described above.
-
If , it is followed by one extra parameter (integer) , as described above.
-
If , it is followed by one extra parameter (integer) , as described above.
-
If , there is no extra parameter.
-
It is guaranteed that .
-
In each line, if there are multiple numbers, they are separated by a single space.
Output Format
- For each purchase event, output one line with two integers separated by a space, representing the sum of the maximum happiness all children can obtain, and the xor sum of the maximum happiness all children can obtain, in this order.
4 10
1 6 10 2
100 2333 666 300
7
3 1 4
3 1 3
1 2 4 1
3 1 4
2 2 3 -1000
2 2 3 -600
3 2 4
15165 2865
14165 2169
36630 798
4899 1273
Hint
Sample Explanation
For the -st purchase event, the maximum happiness each child (in order of indices from to ) can obtain is: .
For the -nd purchase event, the maximum happiness each child (in order of indices from to ) can obtain is: .
For the -rd purchase event, the maximum happiness each child (in order of indices from to ) can obtain is: .
For the -th purchase event, the maximum happiness each child (in order of indices from to ) can obtain is: .
With this information, you can easily compute the answers.
Constraints
It is guaranteed that , , .
It is guaranteed that .
It is guaranteed that , .
Hint
This hint should not have existed, but the kind problem setter still wants to remind you: the sum of the maximum happiness all children can obtain may exceed the range of 32-bit signed integers.
Copyright Information
From the 2018 Tsinghua University Programming Contest and Intercollegiate Invitational (THUPC2018). Thanks to Pony.ai for supporting this contest.
Solutions and other resources can be found at https://github.com/wangyurzee7/THUPC2018.
Translated by ChatGPT 5
京公网安备 11011102002149号