Under construction

Still being built. Things may change

Conic Section

Time limit3sMemory limit256 MB

Summary
Points (i, y) receive single-point updates and range reflections of y, and each query asks for the max of a*x + b*y + c*x*y over an x-range.
Level

Hard9 of 10

Topics
Segment tree, Geometry, Implementation
Solved
No attempts yet

Problem

Rikka generates an integer sequence u1,u2,…u_1, u_2, \ldots as follows. She first generates x1,x2,…x_1, x_2, \ldots with xi=(100000005⋅xi−1+20150609) mod 998244353x_i = (100000005 \cdot x_{i-1} + 20150609) \bmod 998244353, then sets ui=⌊xi/100⌋u_i = \lfloor x_i / 100 \rfloor.

Initially, there are nn points on the Cartesian plane. The ii-th point has coordinates (i,ui mod 100001)(i, u_i \bmod 100001). Then mm operations are performed in order. The ii-th operation is one of three types: C, R, or Q.

Let pi=min⁡{un+2i−1 mod n,un+2i mod n}+1p_i = \min\{u_{n+2i-1} \bmod n, u_{n+2i} \bmod n\} + 1 and qi=max⁡{un+2i−1 mod n,un+2i mod n}+1q_i = \max\{u_{n+2i-1} \bmod n, u_{n+2i} \bmod n\} + 1.

  • If the ii-th operation is C, replace the (un+2i−1 mod n+1)(u_{n+2i-1} \bmod n + 1)-th point with (un+2i−1 mod n+1,un+2i mod 100001)(u_{n+2i-1} \bmod n + 1, u_{n+2i} \bmod 100001).
  • If the ii-th operation is R, replace every point (x,y)(x, y) with pi≤x≤qip_i \le x \le q_i by (x,100000−y)(x, 100000 - y).
  • If the ii-th operation is Q, consider all currently existing points (x,y)(x, y) with pi≤x≤qip_i \le x \le q_i. Given aia_i, bib_i, and cic_i, find max⁡{ai⋅x+bi⋅y+ci⋅x⋅y}\max\{a_i \cdot x + b_i \cdot y + c_i \cdot x \cdot y\} over these points.

Input

The first line contains three integers nn, mm, and x0x_0 (1≤n≤1051 \le n \le 10^5, 1≤m≤1061 \le m \le 10^6, 0≤x0<9982443530 \le x_0 < 998244353, x0≠340787122x_0 \neq 340787122).

Each of the following mm lines starts with a character tit_i, the type of the operation, which is C, R, or Q. If tit_i is Q, three integers aia_i, bib_i, cic_i follow (0≤ai,bi<1060 \le a_i, b_i < 10^6, 0≤ci<400 \le c_i < 40).

It is guaranteed that the number of Q operations does not exceed 10510^5.

Output

For each Q operation, output the maximum value on one line.

Hint

Initially, the three points are at (1,91263)(1, 91263), (2,33372)(2, 33372), and (3,10601)(3, 10601). The first operation changes the third point to (3,94317)(3, 94317).

Examples1

  1. Example 1

    Input
    3 3 2705443
    C
    R
    Q 872784 195599 7
    
    Expected output
    13035048532