luogu#P4743. [Wind Festival] Energy Center

[Wind Festival] Energy Center

Background

[Noon12:13[Noon - 12:13 P.M.]P.M.]

CurtisCurtis NishikinoNishikino saw everyone preparing so seriously for the party, so this cute girl also became a volunteer!

Problem Description

CurtisCurtis NishikinoNishikino came to the energy center of the kite festival, where everyone is preparing for the party. There are a total of NN devices here. Of course, due to changes in the plan, devices may be added or removed at any time. However, the total number of devices will not exceed 10410^4. Keeping track of the number of devices at any time is also one of the volunteer's jobs.

Each device has some attributes. For example, for device ii, for each attribute it has (say attribute jj), there is a given value, denoted as valueijvalue_{ij}. But attributes are shared, which means that even if a device does not have a certain attribute, it only makes its value for that attribute equal to 00. The number of attributes is MM. Note that the attribute indices range from 00 to M1M-1.

Now the volunteers are trying to connect a consecutive segment of devices together, with the following effect:

  • For devices from jj to kk, the final value of attribute ii is p=jkvaluepi\sum_{p=j}^{k}value_{pi}.

The volunteers need CurtisCurtis's help, but doing the calculations is too troublesome. CurtisCurtis NishikinoNishikino also hopes you can help her.

Input Format

The first line contains two integers nn and mm.

In the next nn lines, the first integer is kik_i, meaning device ii has kik_i attributes. Then there are 2×k2\times k integers, xjx_j and yjy_j, meaning valueixj=yjvalue_{ix_j}=y_j.

Then there is an integer qq, meaning there are qq operations. Each operation is one of the following:

II xx: Insert a device after device xx. The next line contains its description, the same as initialization.

DD xx: Discard the xx-th device.

QAQA: Query the total number of devices.

QSQS ll rr: Query the effect of connecting devices ll to rr.

The input is guaranteed to be valid.

Output Format

For each QAQA, output one integer on a single line.

For each QSQS, output mm integers on one line. If the value of attribute ii is 00, output 00 at that position.

Note!

After completing all operations, please output one extra line: "end" (without the double quotes).

4 4
4 0 1 1 2 2 2 3 1
2 0 1 2 1
0
2 1 2 3 1
5
QA
I 2 
2 1 1 3 2
QS 2 4
QA
QS 1 1
4
1 1 1 2
5
1 2 2 1
end

Hint

For 15%15\% of the testdata, 0<N103 , 0<M10 , 0<q1030 < N \le 10^3\ , \ 0<M \le 10\ , \ 0 < q \le 10^3.

For an additional 5%5\% of the testdata, 0<N104 , 0<M200 , 0<q1040<N \le 10^4\ , \ 0<M \le 200\ , \ 0 < q \le 10^4, and it is guaranteed that there are no QSQS operations.

For 100%100\% of the testdata, 0<N104 , 0<M200 , 0<q1040<N \le 10^4\ ,\ 0<M \le 200\ , \ 0<q\le10^4.

Translated by ChatGPT 5