#P12151. Sequence Activation Query
Sequence Activation Query
Sequence Activation Query
Given an integer sequence ( h_i ) of length ( n ), an array of ( n ) pairs ( (a_i,b_i) ) and a positive integer ( k ), you are allowed to perform the following operation on each position ( p ) (each position can be activated at most once):
- Activate \( p \): choose a position \( j \) such that \( 1 \leq j-p \leq k \) and update \( h_p \leftarrow h_p + a_p \) and \( h_j \leftarrow h_j - b_p \).
- Do not activate \( p \).
There are \( q \) queries \( (l_i, r_i, x_i) \). In each query, you are allowed to activate only positions \( p \) in the interval \( [l_i, r_i] \) and if a position \( p \) is activated, the chosen \( j \) must satisfy \( j \in [p+1, \min(p+k, r_i)] \). Determine whether there exists an activation strategy such that the final sequence of values in \( [l_i, r_i] \) satisfies \[ \max_{t=l_i}^{r_i} h_t \le x_i. \]
Note: The queries are independent, i.e. the sequence \( h \) is reset to its original state for each query.
All formulas are given in \( \LaTeX \) format.
inputFormat
The first line contains two integers ( n ) and ( k ).
The second line contains ( n ) integers representing the sequence ( h_i ).
Then ( n ) lines follow, each containing two integers ( a_i ) and ( b_i ).
The next line contains an integer ( q ), the number of queries.
Each of the following ( q ) lines contains three integers ( l_i ), ( r_i ), and ( x_i ) (1-indexed).
outputFormat
For each query, output “Yes” if there exists an activation strategy so that the final maximum value in ( [l_i, r_i] ) is at most ( x_i ), otherwise output “No”.
sample
5 2
1 2 3 4 5
1 1
2 2
3 3
4 4
5 5
3
1 3 3
2 5 5
1 5 6
Yes
No
Yes
</p>