#K46472. Employee Promotion Queries
Employee Promotion Queries
Employee Promotion Queries
You are given N employees with initial skill levels given by an array \(S\). You need to process Q queries. There are two types of queries:
- Query type
0 i x
: Promote the \(i\)-th employee (1-indexed) by increasing their skill by \(x\); that is, update \(S_i = S_i + x\). - Query type
1 x
: Find the employee with the highest index (largest \(i\)) such that \(S_i \ge x\). If no such employee exists, output \(-1\).
For example, if there are 5 employees with initial skills [10, 30, 20, 50, 40]
and the queries are as follows:
1 25 0 3 20 1 45 0 2 25 1 55
Then the answers for the queries of type 1
are 5, 4, 2
respectively.
Note: Input is read from standard input (stdin) and output is written to standard output (stdout).
inputFormat
The first line contains two integers, \(N\) and \(Q\) - the number of employees and the number of queries.
The second line contains \(N\) integers representing the initial skill levels of the employees.
Each of the next \(Q\) lines contains a query in one of the following formats:
0 i x
- Promote the \(i\)-th employee by \(x\) (1-indexed).1 x
- Query to find the employee with the highest index whose skill level is at least \(x\).
outputFormat
For each query of type 1
, output the result on a separate line. The result is the highest index of the employee whose skill is at least \(x\) or \(-1\) if no such employee exists.
5 5
10 30 20 50 40
1 25
0 3 20
1 45
0 2 25
1 55
5
4
2
</p>