#P10734. [NOISG 2019 Prelim] Experimental Charges

[NOISG 2019 Prelim] Experimental Charges

Background

Translated from NOISG2019 Prelim C.Experimental Charges

Problem Description

There are NN charged particles. A particle with a positive electron charge will attract a particle with a negative electron charge, while particles with the same electron charge will repel each other.

There are QQ operations. Each operation is given as Ti,Ai,BiT_i, A_i, B_i, and can be one of three types depending on TiT_i:

  • Operation A means AiA_i and BiB_i attract each other.
  • Operation R means AiA_i and BiB_i repel each other.
  • Operation Q asks, based on the information known so far, what would happen if AiA_i and BiB_i are placed together.

For each Q operation, if they attract each other, output A; if they repel each other, output R; if it cannot be determined, output ?.

It is guaranteed that there is at least one possibility such that all operations are consistent.

Input Format

The first line contains two integers N,QN, Q.

The next QQ lines each contain a character TiT_i and two integers Ai,BiA_i, B_i, describing an operation.

Output Format

Output several lines, each line being the answer to one Q operation.

2 3
Q 1 2
R 1 2
Q 1 2
?
R
4 5
R 1 2
A 2 3
A 1 4
Q 2 4
Q 1 3
A
A

Hint

Sample #1 Explanation

For the first query, the relationship between 11 and 22 cannot be determined, so output ?.

For the second query, it can be determined that 11 and 22 repel each other, so output R.

Constraints

Subtask\text{Subtask} Score N,QN, Q Ti,Ai,BiT_i, A_i, B_i
00 77 N=2,Q10N = 2, Q \leq 10 None
11 1111 None Ai=1A_i = 1 or Bi=1B_i = 1
22 1414 TiT_i can only be R or Q
33 1212 Queries only appear after all relationships are given
44 2525 1N,Q1031 \leq N, Q \leq 10^3 None
55 3131 None

For 100%100\% of the testdata:

  • 1N,Q1051 \leq N, Q \leq 10^5
  • 1AiBiN1 \leq A_i \neq B_i \leq N
  • TiT_i can only be A, R, or Q

Translated by ChatGPT 5