No.2540 Equivalence Testing
タグ : / 解いたユーザー数 6
作問者 : 👑
CuriousFairy315
Note
The execution time limit for this problem is 2500[ms].
Problem Statement
First, let us explain the terminology. Here, a propositional variable means a string consisting of $P$ with a subscript that is a non-negative integer less than $6$, that is, one of $P_0, P_1, P_2, P_3, P_4, P_5$.
A good proposition is a proposition obtained by applying the logical operations $\land, \lor, \Rightarrow$ $0$ or more times to $1$ or more propositional variables. However, to eliminate syntactic ambiguity, both sides are enclosed in parentheses $(,)$ when a logical operation is applied. For example, $(P_0 \land P_0)$ is a good proposition, but $\neg P_0$ is not a good proposition.
Below is an explanation of the definition of good propositions using recursion, for those unfamiliar with propositions. (Click to expand)
We recursively define what it means for a string consisting only of propositional variables, parentheses $(, )$, and the symbols $\land, \lor, \Rightarrow$ to be a good proposition as follows:
- A propositional variable is a good proposition.
- For any good propositions $a$ and $b$, the string $(a \land b)$ obtained by concatenating the strings $($, $a$, $\land$, $b$, and $)$ in this order is a good proposition.
- For any good propositions $a$ and $b$, the string $(a \lor b)$ obtained by concatenating the strings $($, $a$, $\lor$, $b$, and $)$ in this order is a good proposition.
- For any good propositions $a$ and $b$, the string $(a \Rightarrow b)$ obtained by concatenating the strings $($, $a$, $\Rightarrow$, $b$, and $)$ in this order is a good proposition.
Below is an explanation for those unfamiliar with recursive definitions of sets and the like. (Click to expand)
Let $X$ be a set. For example, $X$ may be a set of strings consisting only of specific characters. What we explain here is the phrasing peculiar to mathematics used when recursively defining subsets of $X$ and the like.
For example, using an element $c$ of $X$, non-negative integers $n_0,m_0,n_1,m_1$, and maps $F_0 \colon X^{n_0} \times X^{m_0} \to X$ and $F_1 \colon X^{n_1} \times X^{m_1} \to X$, one may write as follows:
We recursively define a subset $X_0$ of $X$ as follows:
- $c \in X_0$.
- For any $(a,t) \in X_0^{n_0} \times X^{m_0}$, we have $F_0(a,t) \in X_0$.
- For any $(a,t) \in X_0^{n_1} \times X^{m_1}$, we have $F_1(a,t) \in X_0$.
This is only an example; here we used $3$ conditions, but in general there need not be $3$, and relations may be used instead of maps. The general formulation of recursive definitions[1] 6.1.1 Definition is quite abstract, so here we consider only the examples needed to solve this problem.
What is important here is that this definition does not simply mean that $X_0$ is an arbitrary subset of $X$ satisfying all $3$ conditions, but represents the following definition:[1] see 6.1.2 Definition and the paragraph immediately following it
We define the subset $X_0$ of $X$ as the intersection of all subsets $Y$ of $X$ satisfying all of the following $3$ conditions:
- $c \in Y$.
- For any $(a,t) \in Y^{n_0} \times X^{m_0}$, we have $F_0(a,t) \in Y$.
- For any $(a,t) \in Y^{n_1} \times X^{m_1}$, we have $F_1(a,t) \in Y$.
Taking $Y = X$ indeed satisfies the above $3$ conditions, so the set of all $Y$ satisfying the conditions is non-empty and the intersection is defined. It then follows as a result that $X_0$ is the smallest among the $Y$ satisfying the $3$ conditions.
Note that, in this way, a recursive definition of a subset is by convention understood to imply minimality as well, rather than being a mere list of conditions. However, this convention applies only to recursive definitions; an ordinary definition of course does not imply minimality, and in the first place, making a self-reference like that of a recursive definition in an ordinary definition often results in circular reasoning, and the definition breaks down.
Now, since a $1$-ary relation on $X$ is equivalent to a subset of $X$, the same rule applies to recursive definitions of $1$-ary relations on $X$. Specifically,
We recursively define what it means for an element of $X$ to be a good term as follows:
- $c$ is a good term.
- For any $(a,t) \in X^{n_0} \times X^{m_0}$, if every component of $a$ is a good term, then $F_0(a,t)$ is also a good term.
- For any $(a,t) \in X^{n_1} \times X^{m_1}$, if every component of $a$ is a good term, then $F_1(a,t)$ is also a good term.
when a recursive definition of the $1$-ary relation "is a good term" is written like this, it does not mean that the predicate "is a good term" represents an arbitrary $1$-ary relation satisfying the $3$ conditions. The above definition is equivalent to the following definition:
We define an element $x$ of $X$ to be a good term if $x \in Y$ holds for every subset $Y$ of $X$ satisfying all of the following $3$ conditions:
- $c \in Y$.
- For any $(a,t) \in Y^{n_0} \times X^{m_0}$, we have $F_0(a,t) \in Y$.
- For any $(a,t) \in Y^{n_1} \times X^{m_1}$, we have $F_1(a,t) \in Y$.
Based on the above, the recursive definition of good propositions in this problem is equivalent to the following definition:
We define a string $s$ consisting only of propositional variables, parentheses $(, )$, and $\land, \lor, \Rightarrow$ to be a good proposition if, for every set $Y$ consisting only of strings consisting only of propositional variables, parentheses $(, )$, and $\land, \lor, \Rightarrow$, it holds that $s \in Y$ whenever $Y$ satisfies all of the following $3$ conditions:
- Every propositional variable is an element of $Y$.
- For any elements $a$ and $b$ of $Y$, the string $(a \land b)$ obtained by concatenating the strings $($, $a$, $\land$, $b$, and $)$ in this order is an element of $Y$.
- For any elements $a$ and $b$ of $Y$, the string $(a \lor b)$ obtained by concatenating the strings $($, $a$, $\lor$, $b$, and $)$ in this order is an element of $Y$.
- For any elements $a$ and $b$ of $Y$, the string $(a \Rightarrow b)$ obtained by concatenating the strings $($, $a$, $\Rightarrow$, $b$, and $)$ in this order is an element of $Y$.
This is considerably more complicated than the original phrasing. To avoid such complicated phrasing, mathematics defines and adopts the concise phrasing introduced here.
For example, in the references listed later, the following
- the recursive definitions of the $1$-ary relations "be an $\mathcal{L}$-term" and "be an $\mathcal{L}$-formula" in [1], etc.
- the recursive definitions of the set $T$ and the $1$-ary relation "be a principal term" in [2], etc.
- the recursive definitions of the sets $B(\alpha,\beta)$ and $\textrm{K}_{\kappa}(\gamma)$ in [3], etc.
actually adopt such phrasing.
References
- W. Pohlers, "Proof Theory - The first step into impredicativity", Springer, 2010.
- W. Buchholz, "A New System of Proof-Theoretic Ordinal Functions", Annals of Pure and Applied Logic 32 (1986), pp. 195--207.
- M. Rathjen, "Ordinal Notations Based on a Weakly Mahlo Cardinal", Archive for Mathematical Logic 29 (1990), pp. 249--263.
At the beginning of the input, $2$ positive integers $N, Q$ are given.
For each non-negative integer $k$ less than $N$, a good proposition $X_k$ is given as $P_{k \bmod 6}$. Here, $k \bmod 6$ denotes the remainder when $k$ is divided by $6$.
Process the $Q$ queries described below in the given order.
Each query consists of
- a non-negative integer $h$ less than $N$,
- a string $o$ that is one of
land,lor, orRightarrow, - integers $\ell,r$ satisfying $0 \leq \ell \leq r < N$, and
- integers $\ell',r'$ satisfying $0 \leq \ell' \leq r' < N$,
forming a tuple $(h,o,\ell,r,\ell',r')$. Process a query $(h,o,\ell,r,\ell',r')$ as follows:
- First, let the good proposition $Y$ be the value of $X_h$ at this point.
- Next, let the logical operation $O$ be defined as follows: if $o$ is
land, it is $\land$; iflor, it is $\lor$; ifRightarrow, it is $\Rightarrow$. - Then, for each non-negative integer $k$ satisfying $\ell \leq k \leq r$, update the value of $X_k$ by replacing it with the value of $(X_k O Y)$.
- Finally, for the updated values, determine the truth of the proposition "there exist non-negative integers $k_0, k_1$ satisfying $\ell' \leq k_0 < k_1 \leq r'$ such that $X_{k_0}$ and $X_{k_1}$ are equivalent". (Hereafter, this truth value is called the answer to this query.)
Note that the value of $Y$ is fixed at the beginning of processing each query and does not change during the update of $X_k$ for each non-negative integer $k$ satisfying $\ell \leq k \leq r$.
Here is the definition of two propositions being equivalent. (Click to expand)
First, here is a rough explanation for those not familiar with logic. For propositions $a$ and $b$, think of "$a$ and $b$ are equivalent" as meaning that both of the following hold:
- Assuming that $a$ is true, $b$ is true.
- Assuming that $b$ is true, $a$ is true.
For example, $P_1 \land P_1$ and $P_1 \lor P_1$ are equivalent propositions. Indeed, if we assume that $P_1 \land P_1$ is true, then $P_1$ is true, so $P_1 \lor P_1$ is also true; conversely, if we assume that $P_1 \lor P_1$ is true, then again $P_1$ is true, so $P_1 \lor P_1$ is also true. On the other hand, $P_1$ and $P_2$ are not equivalent. Indeed, even if $P_1$ is true, $P_2$ is not necessarily true.
Next, here is a rigorous explanation for those familiar with logic (who know the difference between classical logic and intuitionistic logic). Here, we define "$a$ and $b$ are equivalent" to mean that both of the following hold:
- In classical logic, $b$ is provable assuming $a$.
- In classical logic, $a$ is provable assuming $b$.
Therefore, proof by contradiction, double negation elimination, and the law of excluded middle may all be used to prove the implications in both directions.
Input
Hereafter, for any positive integer $q$ not greater than $Q$, denote the $q$-th query by $(h_q,o_q,\ell_q,r_q,\ell'_q,r'_q)$.
The input is given from standard input in $1 + Q$ lines in the following format:
- Line $1$ contains $N, Q$ separated by half-width spaces.
- For each positive integer $q$ not greater than $Q$, line $1 + q$ contains $h_q,o_q,\ell_q,r_q,\ell'_q,r'_q$ separated by half-width spaces.
$N$ $Q$ $h_1$ $o_1$ $\ell_1$ $r_1$ $\ell'_1$ $r'_1$ $\vdots$ $h_Q$ $o_Q$ $\ell_Q$ $r_Q$ $\ell'_Q$ $r'_Q$
Constraints
This problem has easy-version constraints and hard-version constraints. If all cases satisfying the easy-version constraints get AC, the submission itself is treated as AC. That is, cases that do not satisfy the easy-version constraints but satisfy the hard-version constraints are judged, but they do not affect the status of the submission itself. If the easy-version constraints are not enough for you, or if you have time to spare during the contest, please try the hard-version constraints.
The input of the easy version satisfies the following constraints:
- $N$ is an integer satisfying $1 \leq N \leq 10^6$.
- $Q$ is an integer satisfying $1 \leq Q \leq \textcolor{blue}{10^4}$.
- For any positive integer $q$ not greater than $Q$,
- $h_q$ is an integer satisfying $0 \leq h < N$.
- $o_q$ is one of the strings
land,lor, orRightarrow. - $\ell_q, r_q$ are integers satisfying $0 \leq \ell_q \leq r_q < N$.
- $\ell'_q, r'_q$ are integers satisfying $0 \leq \ell'_q \leq r'_q < N$.
- The sum of $r'_q - \ell'_q$ over all positive integers $q$ not greater than $Q$ is at most $\textcolor{blue}{10^7}$.
Here are the hard-version constraints. (Click to expand)
The input satisfies the following constraints:
- $N$ is an integer satisfying $1 \leq N \leq 10^6$.
- $Q$ is an integer satisfying $1 \leq Q \leq \textcolor{red}{10^5}$.
- For any positive integer $q$ not greater than $Q$,
- $h_q$ is an integer satisfying $0 \leq h < N$.
- $o_q$ is one of the strings
land,lor, orRightarrow. - $\ell_q, r_q$ are integers satisfying $0 \leq \ell_q \leq r_q < N$.
- $\ell'_q, r'_q$ are integers satisfying $0 \leq \ell'_q \leq r'_q < N$.
- The sum of $r'_q - \ell'_q$ over all positive integers $q$ not greater than $Q$ is at most $\textcolor{red}{10^8}$.
When attempting the hard version, using a fast language is recommended. The writer's solution runs in 190[ms] in c++ and 167[ms] in cLay, but in both Python3 and PyPy3 it does not finish within 10000[ms], resulting in TLE.
Output
For each positive integer $q$ not greater than $Q$, if the answer to the $q$-th query is true, print Yes, and if it is false, print No, on line $q$.
Print a newline at the end.
Sample
Sample 1
Input
1 1 0 land 0 0 0 0
Output
No
Initially, $X_0 = P_0$ is given.
The components of the query $(h_1,o_1,\ell_1,r_1,\ell'_1,r'_1)$ are given separated by half-width spaces as 0 land 0 0 0 0. $Y$ is defined as $X_0$ at this point, that is, $P_0$, and the value of $X_0$ is replaced by
$ (X_0 \land Y) = (P_0 \land P_0) $
The query is answered for the updated $X_0 = (P_0 \land P_0)$.
Here, there is no pair of integers $(k_0, k_1)$ satisfying $0 = \ell'_1 \leq k_0 < k_1 \leq r'_1 = 0$ in the first place. Therefore, the answer to the query is false, and we print No.
Sample 2
Input
7 1 3 lor 1 5 0 6
Output
Yes
Initially, $(X_0,X_1,X_2,X_3,X_4,X_5,X_6) = (P_0,P_1,P_2,P_3,P_4,P_5,P_0)$ is given. Note that $X_6$ is $P_0$.
The components of the query $(h_1,o_1,\ell_1,r_1,\ell'_1,r'_1)$ are given separated by half-width spaces as 3 lor 1 5 0 6. $Y$ is defined as $X_3$ at this point, that is, $P_3$, and the value of $(X_0,X_1,X_2,X_3,X_4,X_5,X_6)$ is replaced by
$ (X_0,(X_1 \lor Y),(X_2 \lor Y),(X_3 \lor Y),(X_4 \lor Y),(X_5 \lor Y),X_6) = (P_0,(P_1 \lor P_3),(P_2 \lor P_3),(P_3 \lor P_3),(P_4 \lor P_3),(P_5 \lor P_3),P_0) $
The query is answered for the updated $(X_0,X_1,X_2,X_3,X_4,X_5,X_6) = (P_0,(P_1 \lor P_3),(P_2 \lor P_3),(P_3 \lor P_3),(P_4 \lor P_3),(P_5 \lor P_3),P_0)$.
Here, $(0,6)$ can be chosen as a pair of integers $(k_0, k_1)$ satisfying $0 = \ell'_1 \leq k_0 < k_1 \leq r'_1 = 6$. Since $X_{k_0} = X_0 = P_0$ and $X_{k_1} = X_6 = P_0$, $X_0$ and $X_6$ coincide as propositions, and in particular $X_0$ and $X_6$ are equivalent. Therefore, the answer to the query is true, and we print Yes.
Sample 3
Input
2 2 1 Rightarrow 0 1 0 1 1 Rightarrow 0 0 0 1
Output
No Yes
Initially, $(X_0,X_1) = (P_0,P_1)$ is given.
First, the components of the query $(h_1,o_1,\ell_1,r_1,\ell'_1,r'_1)$ are given separated by half-width spaces as 1 Rightarrow 0 1 0 1. $Y$ is defined as $X_1$ at this point, that is, $P_1$, and the value of $(X_0,X_1)$ is replaced by
$ ((X_0 \Rightarrow Y), (X_1 \Rightarrow Y)) = ((P_0 \Rightarrow P_1), (P_1 \Rightarrow P_1)) $
The query is answered for the updated $(X_0,X_1) = ((P_0 \Rightarrow P_1), (P_1 \Rightarrow P_1))$.
The only pair of integers $(k_0, k_1)$ satisfying $0 = \ell'_1 \leq k_0 < k_1 \leq r'_1 = 1$ is $(0,1)$, and for this $(k_0,k_1)$, $(X_{k_1} \Rightarrow X_{k_0})$ does not necessarily hold, so $X_0$ and $X_1$ are not equivalent. Therefore, the answer to this query is false, and we print No.
Next, the components of the query $(h_2,o_2,\ell_2,r_2,\ell'_2,r'_2)$ are given separated by half-width spaces as 1 Rightarrow 0 0 0 1. $Y$ is defined as $X_1$ at this point, that is, $(P_1 \Rightarrow P_1)$, and the value of $(X_0,X_1)$ is replaced by
$ ((X_0 \Rightarrow Y),X_1) = (((P_0 \Rightarrow P_1) \Rightarrow (P_1 \Rightarrow P_1)), (P_1 \Rightarrow P_1)) $
The query is answered for the updated $(X_0,X_1) = (((P_0 \Rightarrow P_1) \Rightarrow (P_1 \Rightarrow P_1)), (P_1 \Rightarrow P_1))$.
Here, $(0,1)$ can be chosen as a pair of integers $(k_0, k_1)$ satisfying $0 = \ell'_2 \leq k_0 < k_1 \leq r'_2 = 1$.
First, since $X_{k_1} = X_1 = (P_1 \Rightarrow P_1)$ always holds, $(Z \Rightarrow X_{k_1})$ holds regardless of the good proposition $Z$, and in particular $(X_{k_0} \Rightarrow X_{k_1})$ also holds.
Next, since $X_{k_0} = X_0 = (P_0 \Rightarrow (P_1 \Rightarrow P_1))$ is nothing but $(P_0 \Rightarrow X_{k_1})$, if $X_{k_1}$ holds, then $X_{k_0}$ also holds. That is, $(X_{k_1} \Rightarrow X_{k_0})$ holds.
From the above, both $(X_{k_0} \Rightarrow X_{k_1})$ and $(X_{k_1} \Rightarrow X_{k_0})$ hold, so $X_{k_0}$ and $X_{k_1}$ are equivalent. Therefore, the answer to this query is true, and we print Yes.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。