QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#15141. Tricky Operations

Statistics

There are $N$ nodes, labeled from $1$ to $N$, which are initially disconnected. The initial weight of the $i$-th node is $a_i$. There are several types of operations:

  • U x y: Add an edge connecting node $x$ and node $y$.
  • A1 x v: Increase the weight of node $x$ by $v$.
  • A2 x v: Increase the weights of all nodes in the connected component containing node $x$ by $v$.
  • A3 v: Increase the weights of all nodes in the graph by $v$.
  • F1 x: Output the current weight of node $x$.
  • F2 x: Output the maximum weight among all nodes in the connected component containing node $x$.
  • F3: Output the maximum weight among all nodes in the graph.

Input

The first line contains an integer $N$, representing the number of nodes.

The next line contains $N$ integers $a_1, a_2, \ldots, a_N$, representing the initial weights of the $N$ nodes.

The next line contains an integer $Q$, representing the number of operations.

The last $Q$ lines each contain an operation in the format described above.

Output

For each F1, F2, and F3 operation, output the corresponding result on a new line.

Examples

Input 1

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

Output 1

-10
10
10

Subtasks

For $30\%$ of the data, $N \le 100$ and $Q \le 10^4$.

For $80\%$ of the data, $N \le 10^5$ and $Q \le 10^5$.

For $100\%$ of the data, $N \le 3 \times 10^5$ and $Q \le 3 \times 10^5$.

For all data, it is guaranteed that the input is valid and $-10^3 \le v, a_1, a_2, \ldots, a_N \le 10^3$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.