#P13704. [NWERC 2023] Exponentiation

[NWERC 2023] Exponentiation

题目描述

In her spare time, Zoe develops an online calculator. Unfortunately, the calculator was targeted by a denial-of-service attack last week. The attacker created a lot of integer variables, exponentiated them with each other, and tried to do a bunch of comparisons. The huge integers were too much for the server to handle, so it crashed. Before Zoe fixes the issue, she decides to actually perform the calculations that the attacker requested.

图片太大了传不上洛谷

:::align{center} Image by callmetak on Freepik :::

There are nn integer variables x1,x2,,xnx_1, x_2, \dots, x_n. At the start, each variable is set to 20232023. You have to perform mm instructions of the following two types:

  • Operations, of the form "! i j\texttt{! i j}", where iji \neq j. This means that xix_i gets set to xixjx_i^{x_j}.
  • Queries, of the form "? i j\texttt{? i j}", where iji \neq j. This means that you should print '>\verb|>|' if xix_i is greater than xjx_j, '=\verb|=|' if xix_i is equal to xjx_j, and '<\verb|<|' if xix_i is smaller than xjx_j.

Consider the first sample. After the 55 operations, the values of the variables are:

$$\begin{align*} x_1&=\left({2023}^{2023}\right)^{{2023}^{2023}},& x_2&=\left({2023}^{{2023}^{2023}}\right)^{2023},& x_3&={2023},& x_4&={2023}^{2023}. \end{align*} $$

输入格式

The input consists of:

  • One line with two integers nn and mm (2n10002 \leq n \leq 1000, 1m10001 \leq m \leq 1000), the number of variables and the number of instructions.
  • mm lines, each containing a character cc (either '!\texttt{!}' or '?\texttt{?}') and two integers ii and jj (1i,jn1 \leq i, j \leq n, iji \neq j), describing the instructions.

输出格式

For every query in the input, output its answer.

4 8
! 1 4
! 2 1
! 4 3
! 1 4
! 2 3
? 3 4
? 2 4
? 2 1
<
>
=

4 9
! 2 4
! 1 2
? 3 1
? 1 2
! 2 3
? 1 2
! 1 3
! 3 2
? 1 3
<
>
>
<