#P3273. [SCOI2011] 棘手的操作

    ID: 2322 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2011四川线段树深度优先搜索,DFS连通块

[SCOI2011] 棘手的操作

Description

There are NN nodes labeled from 11 to NN, initially all disconnected. The initial weight of the ii-th node is aia_i. Then the following operations occur:

  • U x y: add an edge connecting node xx and node yy.
  • A1 x v: increase the weight of node xx by vv.
  • A2 x v: increase the weights of all nodes in the connected component containing node xx by vv.
  • A3 v: increase the weights of all nodes by vv.
  • F1 x: output the current weight of node xx.
  • F2 x: output the maximum weight within the connected component containing node xx.
  • F3: output the maximum weight among all nodes.

Input Format

The first line contains an integer NN, the number of nodes. The second line contains NN integers a1,a2,,aNa_1,a_2,\dots,a_N, the initial weights of the NN nodes.

The next line contains an integer QQ, the number of subsequent operations.

Each of the following QQ lines is in one of the formats described above.

Output Format

For operations F1 x, F2 x, and F3, output the corresponding result, one per line.

3
0 0 0
8
A1 3 -20
A1 2 20
U 1 3
A2 1 10
F1 3
F2 3
A3 -10
F3
-10
10
10

Hint

Constraints:

  • For 30%30\% of the testdata, N100N \le 100, Q10000Q \le 10000.
  • For 80%80\% of the testdata, N100000N \le 100000, Q100000Q \le 100000.
  • For 100%100\% of the testdata, N300000N \le 300000, Q300000Q \le 300000.
  • For all testdata, the input is guaranteed to be valid, and 1000v,a1,a2,,aN1000-1000 \le v, a_1, a_2, \dots, a_N \le 1000.

Translated by ChatGPT 5