Under construction

Still being built. Things may change

Analyzing Contracts

Time limit1sMemory limit1024 MB

Summary
Clients are added with an end day and daily revenue, and each supplier query asks for the maximum profit from matching an available client to that supplier.
Level

Hard8 of 10

Topics
Geometry, Segment tree, Divide and conquer
Solved
No attempts yet

Problem

Doctor Kruskal is starting a tiberium trading business. There are N possible suppliers of tiberium, and many clients want to receive tiberium to run their industries. Calendar days are numbered with positive integers, and each supplier is identified by a distinct integer from 1 to N. Supplier i can supply tiberium from day SiS_i onwards, but not on earlier days. The supplier charges PiP_i dollars per day. The list contains only the best suppliers in the city, so Si<Si+1S_i < S_{i+1} and Pi>Pi+1P_i > P_{i+1} for i=1,…,N−1i = 1, \dots, N-1.

Input

The first line contains N (1≤N≤2×1051 \le N \le 2 \times 10^5). Each of the next N lines contains SiS_i and PiP_i (1≤Si,Pi≤1091 \le S_i, P_i \le 10^9). The next line contains Q (1≤Q≤2×1051 \le Q \le 2 \times 10^5). Each of the next Q lines is either c E R (1≤E,R≤1091 \le E, R \le 10^9), which adds a client with end day E and daily revenue R to the database, or s I (1≤I≤N1 \le I \le N), which asks for the maximum profit for supplier I. At least one operation of the second type appears.

Output

For each operation of type s, print one line with the maximum possible profit from matching an available client with the given supplier. Print the results in the order the operations appear in the input.

Examples1

  1. Example 1

    Input
    4
    2 8
    4 5
    7 3
    9 2
    11
    s 1
    c 10 10
    s 1
    s 2
    s 3
    s 4
    c 7 26
    s 2
    s 4
    s 3
    s 1
    
    Expected output
    0
    18
    35
    28
    16
    84
    16
    28
    108