#C7986. Bookstore Inventory Management
Bookstore Inventory Management
Bookstore Inventory Management
You are given a bookstore inventory system that tracks the number of copies of a book sold over a sequence of days. The system supports two types of queries and one update operation:
- Update: Update the sales figure for a particular day.
- Total Sales Query: Given a range of days, compute S = \(\sum_{i=start}^{end} a_i\), where \(a_i\) is the number of copies sold on day \(i\).
- Maximum Sales Query: Given a range of days, return the 1-indexed day which recorded the maximum number of copies sold. In case of ties, return the smallest day index.
You need to process a series of commands provided via standard input and output the result of each query (except update commands, which output nothing) to standard output.
inputFormat
The input is given via standard input (stdin) in the following format:
n a1 a2 ... an q command1 command2 ... commandq
Here:
- \(n\) (integer) is the number of days.
- \(a_1, a_2, ..., a_n\) are the initial copies sold on each day.
- \(q\) is the number of commands.
- Each command is given on a new line and can be one of the following three types:
1 d c
: Update the number of copies sold on day \(d\) to \(c\).2 i j
: Query the total number of copies sold from day \(i\) to day \(j\) (inclusive).3 i j
: Query the day (1-indexed) with the maximum copies sold between day \(i\) and day \(j\) (inclusive). If there are multiple days with the same maximum, choose the earliest.
outputFormat
For each command of type 2
and 3
, output the result (an integer) on a new line to standard output (stdout). Type 1
commands do not produce any output.
5
5 8 6 3 7
5
2 1 5
3 1 5
1 3 10
2 1 5
3 3 5
29
2
33
3
</p>