luogu#P4879. ycz的妹子
ycz的妹子
Background
ycz has a lot, a lot of girls (ycz: just kidding).
Problem Description
The legendary ycz has childhood sweethearts, and they live in cities numbered . 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 to mean that the girl in city has her looks decreased by .
After growing up, ycz became very charming, and many girls fell for him. We use to mean that in city a girl appears who likes ycz, and her looks value is ( may be negative, but ycz accepts everyone). However, some girls quarrel with ycz and then break up. We use to mean that the -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 -th girl to break up is not the girl in city . It means the girl in the -th city (counting from left to right) that currently has a girl.
Childhood sweethearts become “girls” after growing up.
The modified value is not negative, but the looks value may become negative after subtraction.
Input Format
ycz has cities. Initially, each of the first cities has one girl, and the initial looks value of the girl in city is .
There are operations of the following four types.
C x yThe looks value of the girl in city decreases by .I x yA girl with looks value appears in city . If there was already a girl in city before, the previous girl is driven away.D xThe girl in the -th city (among the cities that currently have a girl) breaks up with ycz.Qycz 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, .
For 70% of the testdata, .
For 100% of the testdata, .
Translated by ChatGPT 5