Pretty Pens

시간 제한2초메모리 제한2048 MB

요약
M개 색마다 펜을 하나씩 골라 아름다움 합을 최대로 만들되 펜 하나의 색을 바꿀 수 있을 때, 각 갱신 뒤의 최댓값을 구한다.
난이도

어려움10점 중 8점

유형
그리디, 정렬, 구현, 해시맵
정답자
아직 제출이 없습니다

문제

You are taking an art class, and your current art assignment is very algorithmic.

You have NN pens, each of which has a single colour, represented by an integer from 11 to MM. Initially, the colour of the ii-th pen is given by C_i\_i. In addition, your pens are pretty, with the ii-th pen having a prettiness of P_iP\_i.

For your assignment, you need to create a picture using MM strokes, each from a pen of a different colour. The prettiness of your picture is the sum of the prettiness of the pens used to create the picture.

Your teacher has given you some room for artistic expression: before you create this pretty picture, you are allowed to change at most one pen to any other colour. After this picture is drawn, the pen will revert back to its original colour.

Your teacher will give you 13\frac{1} {3} of the marks (55 of 1515 total marks) for the art assignment based on creating the prettiest picture you can.

To push your creative limits, your teacher also has QQ more pictures for you to create, which compose the remaining 23\frac{2}{3} of the marks (1010 of 1515 total marks) for your art assignment. Before each picture, there will be one of two possible changes to the set of pens available:

  • 11 ii cc indicates that the colour of the ii-th pen changes to cc.
  • 22 ii pp indicates that the prettiness of the ii-th pen changes to pp.

The changes are executed sequentially (so the first change modifies the initial setup, the second change modifies the result of applying the first change, and so on).

As in the first picture you created, you are allowed to change the colour of at most one pen before the picture is created. Note that if you do change the colour of one pen, it affects only the next picture you draw, and the pen will revert to its previous colour before the next change is applied (if any).

What is the prettiness of the prettiest Q+1Q + 1 pictures you can create?

입력

The first line of input contains three space-separated integers NN, MM, and QQ (1≤M≤N≤200,0001 ≤ M ≤ N ≤ 200\\, 000, 0≤Q≤200,0000 ≤ Q ≤ 200\\, 000).

The next NN lines each contain two space-separated integers, C_iC\_i and P_iP\_i (1≤C_i≤M1 ≤ C\_i ≤ M, 1≤P_i≤1091 ≤ P\_i ≤ 10^9), indicating the colour and prettiness of the ii-th pen.

The next QQ lines each contain three space-separated integers, beginning with 11 or 22. If the first integer is 11, it is followed by two integers i_ji\_j and c_jc\_j (1≤i_j≤N1 ≤ i\_j ≤ N, 1≤c_j≤M1 ≤ c\_j ≤ M), representing a change of the colour of the i_j\_j-th pen to c_jc\_j. If the first integer is 22, it is followed by two integers i_ji\_j and p_jp\_j (1≤i_j≤N1 ≤ i\_j ≤ N, 1≤p_j≤1091 ≤ p\_j ≤ 10^9 ), representing a change of the prettiness of the i_ji\_j-th pen to p_jp\_j.

It is guaranteed that initially and after each change, there is at least one pen with each of the MM colours.

출력

The output is Q+1Q + 1 lines, with the jj-th line containing one integer, the largest possible prettiness value obtainable after the first j−1j − 1 changes have been performed.

예제2

  1. 예제 1

    입력
    6 3 0
    1 6
    2 9
    3 4
    2 7
    3 9
    1 3
    
    예상 출력
    25
    
  2. 예제 2

    입력
    3 2 2
    1 20
    2 30
    1 10
    1 3 2
    2 3 25
    
    예상 출력
    50
    50
    55