#C8695. Factory Production Analysis

    ID: 52705 Type: Default 1000ms 256MiB

Factory Production Analysis

Factory Production Analysis

In this problem, you are required to simulate the production tracking of a factory that manufactures two products: Product A and Product B. The factory operates for 365 days. You will process two kinds of operations:

  1. Update Operation: Update the production of a specific product on a given day. The input for an update is in the format:

1 P x y d

Where P is the product type (1 for Product A and 2 for Product B), x and y denote the production units for Product A and B respectively (only one of them will be non-zero in an update), and d is the day number (1 ≤ d ≤ 365).

  1. Analysis Operation: Analyze the production over an interval [d1, d2] for a specific product. For a query,

2 P m d1 d2

P is the product type (1 for Product A and 2 for Product B), m indicates the number of days to consider from the end of the interval, and d1, d2 denote the starting and ending days of the interval. The answer is the sum of production units for the specified product over the last ( \min(m, d2-d1+1) ) days in that interval.

Your task is to implement these operations and output the result of each analysis operation immediately to stdout. Input is read from stdin and output is printed to stdout.

inputFormat

The first line contains an integer Q, the number of queries. Each of the next Q lines represents a query in one of the following forms:

  1. For an update operation:   1 P x y d

    • P: Product type (1 for Product A, 2 for Product B).
    • x: Production units for Product A (update only if P==1).
    • y: Production units for Product B (update only if P==2).
    • d: The day number.
  2. For an analysis operation:   2 P m d1 d2

    • P: Product type (1 for Product A, 2 for Product B).
    • m: The number of days to consider from the end of the interval [d1,d2].
    • d1, d2: The starting and ending days of the interval.

outputFormat

For each analysis query (query type 2), output a single integer on a new line which represents the sum of production units of the specified product over the considered days.## sample

3
1 1 500 0 1
1 2 0 300 2
2 1 2 1 2
500

</p>