The team's players stand in a line, numbered from to , and player has skill . The coach stands at the left end of the line, takes any ball passed to him and passes nothing back, because the coach doesn't play. Romanian football has an old touchline call, short on two, which means a short pass to your nearest teammate. The coach considers it far too generous to whoever happens to stand nearby, so at his club the ball goes short on three, still short, but always to someone strictly better.
A group consists of the players at some consecutive positions. At the start of a training exercise, every player in the group has a ball at his feet, and the coach moves immediately to the left of the group. Then each player passes the ball he started with and keeps any ball he receives: his ball goes to the closest player on his left, within the group, whose skill is strictly greater than his own, and if no such player exists, it goes to the coach.
Formally, number the players of the group from to , from left to right, let be the skill of the -th of them, and let the coach stand at position . For every from to , the position within the group to which player passes his ball is
For example, for skills we get : the third player skips the second, whose skill is not better than his.
The coach calls a group disciplined if the sequence is a mountain, meaning that there is a position with such that . He has never explained why, and nobody has asked twice, because the coach doesn't play around either.
Over the season there are transfers, applied one after another. A transfer is described by two integers and , and it permanently replaces the player at position of the line with a new player of skill , who stands on the same spot.
Task
After every transfer, the coach wants to know the maximum number of players in a disciplined group.
Implementation details
This is a function-implementation task. Your program must not read from standard input or write to standard output. You must include the header shortonthree.h and implement the following two functions, without implementing a main function:
void init(int N, std::vector<int> v);
int transfer(int pos, int val);
The function init is called exactly once in the beginning.
- : the number of players.
- : a vector of length , where is the skill of player , for .
After the initial call to init, the function transfer is called exactly times, once for each transfer, in the order in which the transfers happen.
- , : the player at position (numbered from ) is replaced with a new player of skill .
- The function must return the maximum number of players in a disciplined group after this transfer.
Restrictions
- .
- .
- .
| # | Points | Restrictions |
|---|---|---|
| 0 | 0 | Examples. |
| 1 | 9 | |
| 2 | 15 | |
| 3 | 18 | Every and every is or . |
| 4 | 26 | |
| 5 | 32 | No additional constraints. |
Examples
Sample grader input
6 2
1 2 1 3 2 5
1 3
3 1
Sample grader output
4
6
Explanation
The sample grader makes the following calls:
init(6, {1, 2, 1, 3, 2, 5});
transfer(1, 3);
transfer(3, 1);
- After the first transfer, the skills are . The group on positions to , with skills , gives , which is a mountain. It can be shown that no group of or players is disciplined; the whole line, for instance, gives , which is not a mountain. So
transfer(1, 3)returns . - After the second transfer, the skills are , and the whole line is one disciplined group, with . So
transfer(3, 1)returns .