#P6859. 蝴蝶与花

蝴蝶与花

Background

Amazing John had a dream that in his previous life he was a vast, misty butterfly.

Deep ravines and hidden orchids, rain falling into the boundless haze.

Pity its broken wings, sorrow for its stubborn obsession.

Jade-like flakes weave wings, flower dew sees it off.

A lonely butterfly shatters, the orchid withers yet still has feelings.

You do not know me, yet I still miss you.

Problem Description

Amazing John likes flowers very much.

There are nn flowers in Amazing John's garden, and every day he takes a walk in it.

For each flower, Amazing John will judge it as beautiful or not beautiful. A flower judged as beautiful has beauty value 22, and a flower judged as not beautiful has beauty value 11.

We can abstract these nn flowers as being on a straight line. During each walk, Amazing John may start from any flower and keep moving to the next flower, and end at any flower. Along the way, he sums up the beauty values of all flowers he passes (including the starting flower and the ending flower).

Now Amazing John wants to know whether there exists a walking plan such that the sum of beauty values from the ll-th flower to the rr-th flower is exactly ss.

To walk less, among all valid plans, Amazing John asks you to output the plan with the smallest ll.

Of course, to avoid the walk being too boring, Amazing John may change the beauty value of a flower at any time.

Each query is independent. That is, flowers counted in one query can still be counted in the next query.

Input Format

The first line contains two numbers n,mn,m, representing the number of flowers and the number of requests from Amazing John.

The second line contains nn numbers aia_i, where aia_i is the beauty value of the ii-th flower.

The next mm lines each describe either a query operation or a modification operation.

The query operation format is A s, asking whether there exists a walking plan such that the sum of beauty values is ss.

The modification operation format is C i val, meaning to change the beauty value of the ii-th flower to val(val=1val(val=1 or 2)2).

Output Format

If there are qq operations of type A, the output should contain qq lines.

For each query, if there is a valid plan, output the left and right endpoint positions of that plan (if there are multiple plans, output the one with the smallest left endpoint). Otherwise, output none.

You should guarantee that 1lrn1\leq l\leq r\leq n.

5 4
1 2 2 1 1
A 5
C 1 2
A 5
A 233
1 3
2 4
none

Hint

Subtask 1 (20pts)\operatorname{Subtask\ 1}\ (20pts): For testdata points 151\sim 5, 1n,m10001\leq n,m\leq 1000.

Subtask 2 (30pts)\operatorname{Subtask\ 2}\ (30pts): For testdata points 6106\sim 10, 1n,m2.5×1051\leq n,m\leq 2.5\times 10^5.

Subtask 3 (50pts)\operatorname{Subtask\ 3}\ (50pts): For testdata points 111511\sim 15, 1n,m2×1061\leq n,m\leq 2\times 10^6.

For 100%100\% of the testdata, 1n,m2×106,0s23111\leq n,m\leq 2\times 10^6,0\leq s\leq 2^{31}-1. For each modification operation, i[1,n],val{1,2}i\in[1,n],val\in\{1,2\}.

For all testdata points, the time limit is 2000ms2000\operatorname{ms} and the memory limit is 256MB256\operatorname{MB}.

Translated by ChatGPT 5