#P7028. [NWRRC 2017] Joker

[NWRRC 2017] Joker

题目描述

Joker prepares a new card trick with a strong mathematical background. You are asked to help Joker with calculations.

There is a row of nn cards with non-zero numbers aia_{i} written on them. Let's call the sum of all positive numbers PP and the sum of all negative numbers NN . Every card ii has a weight wi=ai/Pw_{i} = a_{i}/P if ai>0a_{i} > 0 and ai/Na_{i}/|N| otherwise.

Let's denote si=(j=1jiwj)s_{i} = ( \sum_{j=1}^{j \le i}{w_j}). Joker needs to know positive ii with the largest si.s_{i}. If there is more than one such ii , he is interested in the smallest one.

But static tricks are boring, so Joker wants to change numbers on some cards, and after each change he needs to known where is the largest sis_{i} is.

输入格式

The first line of the input contains two integers nn and mm -- the number of cards and the number of changes (1n,m50000)(1 \le n , m \le 50 000) .

The second line consists of nn integers aia_{i} -- numbers written on cards at the beginning (109ai109;ai0)(−10^{9} \le a_{i} \le 10^{9}; a_{i} ≠ 0) .

The following mm lines contain two integers each: pip_{i} and vi,v_{i}, that means value of card at position pip_{i} is changed to vi(1pinv_{i} (1 \le p_{i} \le n ; 109vi109;vi 0)−10^{9} \le v_{i} \le 10^{9}; v_{i} ≠ 0) .

It is guaranteed that at each moment there is at least one card with positive number and at least one card with negative number. The sum of all positive cards will never exceed 10910^{9} and the sum of all negative cards will never exceed 109.−10^{9}.

输出格式

You should output m+1m+1 integers. The first integer is the position of the largest sis_{i} for the initial numbers. Next mm numbers are positions of the largest sis_{i} after each change.

4 7
1 -5 3 -5
4 -1
2 -1
3 10
4 10
1 -1
2 1
3 -1

3
1
3
3
1
4
4
4

提示

Time limit: 3 s, Memory limit: 512 MB.