#P5618. [SDOI2015] 道路修建

[SDOI2015] 道路修建

Description

A certain country has 2N2N cities. These 2N2N cities form a 22-row, NN-column grid. The government now has a tourism development plan: it needs to choose two columns LL and RR (LR)(L \leq R), and build some dedicated roads so that among all 2(RL+1)2(R-L+1) cities between these two columns (including these two columns), every city can reach any other of these 2(RL+1)2(R-L+1) cities using only the dedicated roads.

A dedicated road can only be built between two cities in the same row and adjacent columns, or between the two cities in the same column, and building a road costs some amount.

Since the government wants to reduce expenses as much as possible, after choosing LL and RR, it will build only 2(RL+1)12(R-L+1)-1 dedicated roads, so that these roads form a tree structure. Now you need to help the government write a program to complete this task.

Specifically, the task contains MM operations, each in one of the following formats:

  1. C x0 y0 x1 y1 w: Because the situation between the city at row x0x_0, column y0y_0 and the city at row x1x_1, column y1y_1 has been re-evaluated, the cost to build a dedicated road between them becomes ww.

  2. Q L R: If the government chooses columns LL and RR, ask for the minimum total expense.

Input Format

The first line contains two integers NN and MM.

The second line contains N1N-1 integers. The ii-th integer indicates the initial cost to build a dedicated road between the city at row 11, column ii and the city at row 11, column i+1i+1.

The third line contains N1N-1 integers. The ii-th integer indicates the initial cost to build a dedicated road between the city at row 22, column ii and the city at row 22, column i+1i+1.

The fourth line contains NN integers. The ii-th integer indicates the initial cost to build a dedicated road between the city at row 11, column ii and the city at row 22, column ii.

The next MM lines each contain one operation.

Output Format

For each query operation, output one line containing the minimum expense you computed for the government.

3 3
1 2
2 1
3 1 2
Q 1 3
C 1 2 2 2 3
Q 2 3
7
5

Hint

For all testdata, 1N,M600001 \leq N, M \leq 60000, and at any time, the construction cost of any dedicated road does not exceed 10410^4.

Translated by ChatGPT 5