luogu#P4879. ycz的妹子

ycz的妹子

Background

ycz has a lot, a lot of girls (ycz: just kidding).

Problem Description

The legendary ycz has nn childhood sweethearts, and they live in cities numbered 1n1 \sim n. When they were young, they were pretty and cute. But as time went by, some girls’ looks changed. Since ycz is very sentimental and cannot bear to abandon them, he recorded the amount of change in their looks.

We use C,x,yC, x, y to mean that the girl in city xx has her looks decreased by yy.

After growing up, ycz became very charming, and many girls fell for him. We use I,x,yI, x, y to mean that in city xx a girl appears who likes ycz, and her looks value is yy (yy may be negative, but ycz accepts everyone). However, some girls quarrel with ycz and then break up. We use D,xD, x to mean that the xx-th girl breaks up with ycz.

Recently, ycz is going to visit his girls all around the country. For easier calculation, we can treat the cities where his girls are as points on a straight line, placed next to each other. ycz is already tired from keeping in touch with his girls, so he gives you this task:

He wants to know, at some time, how much “happiness” he can get by visiting all of his girls. This happiness is defined as the sum of the girls’ looks values he visits. Your job is to compute this sum (note that after growing up, a girl’s looks value may be negative).

Note: Each city is allowed to have only one girl. That is, a girl who appears later in a city will drive away the previous girl in that city (two girls cannot share one city).

UPD:

Childhood sweethearts all like ycz.

The xx-th girl to break up is not the girl in city xx. It means the girl in the xx-th city (counting from left to right) that currently has a girl.

Childhood sweethearts become “girls” after growing up.

The modified value yy is not negative, but the looks value may become negative after subtraction.

Input Format

ycz has 5×1055 \times 10^5 cities. Initially, each of the first nn cities has one girl, and the initial looks value of the girl in city ii is aia_i.

There are mm operations of the following four types.

  • C x y The looks value of the girl in city xx decreases by yy.
  • I x y A girl with looks value yy appears in city xx. If there was already a girl in city xx before, the previous girl is driven away.
  • D x The girl in the xx-th city (among the cities that currently have a girl) breaks up with ycz.
  • Q ycz wants to know the total sum of looks values of all his girls.

Output Format

For each Q, output one integer.

5 10
1 2 3 4 5
Q
C 3 2
Q
I 6 6
Q
D 4
Q
C 5 2
I 7 9
Q
15
13
19
15
22

Hint

Sample explanation:

The looks values change as follows. Deleted ones are not written below.

1 2 1 4 5
1 2 1 4 5 6
1 2 1 5 6
1 2 1 3 6
1 2 1 3 6 9

For 30% of the testdata, 1n,m101 \le n,m \le 10.

For 70% of the testdata, 1n,m10001 \le n,m \le 1000.

For 100% of the testdata, 1n,m100000,ai,y1091 \le n,m \le 100000,|a_i|,|y| \le 10^9.

Translated by ChatGPT 5