Black Debt
Time limit1sMemory limit512 MB
Contestants get point increases over time; after each update, report the total count of (yellow, black) pairs where the black contestant has strictly more points.
- Level
Hard8 of 10
- Topics
- Segment tree, Binary search, Sorting, Prefix sum
- Solved
- No attempts yet
Problem
contestants take part in a programming competition. Before the competition, Mr. Malnar gave each contestant a shirt. Some contestants got yellow shirts and some got black shirts, which created a rivalry between the black team and the yellow team.
At the start of the competition every contestant has 0 points, and the color of each contestant's shirt is known. During the competition there are changes in the scores. In the -th change, contestant has just received more points.
Each contestant in a yellow shirt computes their penalty (the so-called black debt) as the number of contestants in black shirts who at that moment have strictly more points than they do. After each change in the scores, compute and print the sum of the penalties of the contestants in yellow shirts.
Input
The first line contains the positive integers () and () from the problem statement.
The next line contains a string of characters describing the shirt color of each contestant. Each character in that string is one of the uppercase letters C or Z, denoting the shirt color of the -th contestant (black or yellow). There will be at least one contestant with a black shirt and at least one contestant with a yellow shirt.
The following lines each contain two positive integers () and ().
The maximum number of points a contestant can score in the competition is .
Output
In the -th of the lines of output, print the total black debt after the -th change.