P29805 [洛谷] Tears
提高
题目描述

Problem Background

"Why are you crying?"

"Because my expectations are far from reality."

"What can crying change?"

"Nothing. Just like the past that has already happened."

"Then why not wipe away your tears and move forward?"

"...I'm waiting for my soul to catch up with time."

After night

Long night之后

In boundless light

无垠光中

He calls my name

他呼唤着我

I do the same

我望向彼方,回应

Problem Description

"Don't think about things you don't want to remember. To distract you, I have a problem related to human emotions. How about it?"

"...It's really吐槽able. How come it's always that person dominating?"

"What's wrong with that? You used to be very passionate about such things."

"...Maybe."

"Ahem...listen carefully. There are $n$ people, each with an emotional value represented by a real number $v_i$. Due to some special changes, these people's emotions have become entangled..."

"Hmm?"

"The first type of entanglement has four parameters $a, b, c, d$, indicating: there exist infinitely many $f:\R\rightarrow\R$ such that $\frac{f(v_a)}{f(v_b)}=\frac{v_c}{v_d}$."

"Wait, wait! How did this mathematical formula come up? What does $f:\R\rightarrow\R$ mean?"

"Look, you said it too."

"...Damn, it's really you, that person..."

"Simply put, $f:\R\rightarrow\R$ represents a function with both domain and range being real numbers. If you can't understand this, I'll start to doubt your identity as a high school student..."

"Alright...continue."

"The second type of entanglement has two parameters $a, b$, indicating: there exist finitely many $f:\R\rightarrow\R$ such that $f(v_a)\ne f(v_b)$."

"What does 'finitely many' mean?"

"It means there's a definite number...As long as there's a natural number $k$ that can represent the number of such functions, then it's called 'there exist finitely many functions', okay?"

"Hmm..."

"Next, as the entanglements increase, you also need to answer some questions. The first type is, given $a, b$, you need to determine if $v_a$ is always equal to $v_b$; the second type is, given $a$, you need to calculate how many $b$ ($1\le b\le n$, $b$ can be equal to $a$) such that $v_a=v_b$ always holds."

"...I understand the problem, but what does this have to do with human emotions?"

"Haha...I just wanted to cheer you up, don't be so serious."

"...Boring."

Brief Problem Statement

There are $n$ positive real number variables $v_1, \dots, v_n$. You need to make judgments based on the current known conditions. Each time, you are given one of two conditions:

  • Given constants $a, b, c, d$: indicating there exist infinitely many $f:\R\rightarrow\R$ such that $\frac{f(v_a)}{f(v_b)}=\frac{v_c}{v_d}$.

  • Given constants $a, b$: indicating there exist finitely many $f:\R\rightarrow\R$ such that $f(v_a)\ne f(v_b)$.

Or one of two queries:

  • Given constants $a, b$: ask if $v_a=v_b$ always holds.

  • Given constant $a$: ask how many $b$ ($1\le b\le n$, $b$ can be equal to $a$) such that $v_a=v_b$ always holds.

Input Format

The first line contains two positive integers $n, m$, representing the number of variables and the number of operations, respectively.

The next $m$ lines, each representing an operation, can be one of four types:

  • 1 a b c d: indicating there exist infinitely many $f:\R\rightarrow\R$ such that $\frac{f(v_a)}{f(v_b)}=\frac{v_c}{v_d}$.

  • 2 a b: indicating there exist finitely many $f:\R\rightarrow\R$ such that $f(v_a)\ne f(v_b)$.

  • 3 a b: ask if $v_a=v_b$ always holds.

  • 4 a: ask how many $b$ ($1\le b\le n$, $b$ can be equal to $a$) such that $v_a=v_b$ always holds.

Output Format

For each operation of type three, output a line with the string entangled if $v_a=v_b$ always holds; otherwise, output a line with the string separate.

For each operation of type four, output a line with an integer representing the number of $b$ that meet the condition.

Sample Input and Output

Sample Input #1

2 2
2 1 2
3 1 2

Sample Output #1

entangled

Sample Input #2

5 7
1 1 2 3 4
3 1 2
2 1 2
3 1 2
3 3 4
4 1
4 2

Sample Output #2

separate
entangled
entangled
2
2

Sample Input #3

7 6
1 1 2 3 4
1 3 5 6 7
2 4 5
3 6 7
2 1 2
3 6 7

Sample Output #3

separate
entangled

Notes

For all data, $1\le n, m\le 6\times 10^5$. It is guaranteed that in operation one, $a\ne b, c\ne d$, in operation two, $a\ne b$, and in operation three, $a\ne b$.

Subtask 1 (5 pts): Guaranteed not to have operation one and operation two.

Subtask 2 (10 pts): Guaranteed not to have operation one.

Subtask 3 (35 pts): Guaranteed $n\le 5000$.

Subtask 4 (50 pts): No special restrictions.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 2 2 1 2 3 1 2
样例输出
entangled