题目描述
To store long DNA sequences, your company has developed a $\text{LongLongString}$ class that can store strings with more than ten billion characters. The class supports two basic operations:
- $\text{Ins}(p, c)$: Insert the character $c$ at position $p$.
- $\text{Del}(p)$: Delete the character at position p.
A DNA editing program is written as a series of $\text{Ins}$ and $\text{Del}$ operations. Your job is to write a program that compare two DNA editing programs and determine if they are identical, i.e., when applied to any sufficiently long string, whether the end result is the same. For example:
- $\text{Del}(1)$ $\text{Del}(2)$ and $\text{Del}(3)$ $\text{Del}(1)$ are identical.
- $\text{Del}(2)$ $\text{Del}(1)$ and $\text{Del}(1)$ $\text{Del}(2)$ are different.
- An empty sequence and $\text{Ins}(1, x)$ $\text{Del}(1)$ are identical.
- $\text{Ins}(14, b)$ $\text{Ins}(14, a)$ and $\text{Ins}(14, a)$ $\text{Ins}(15, b)$ are identical.
- $\text{Ins}(14, a)$ $\text{Ins}(15, b)$ and $\text{Ins}(14, b)$ $\text{Ins}(15, a)$ are different.
输入格式
Input will consist of the descriptions of two DNA editing programs. Each program will consist of some number of operations (between $0$ and $2,000$). Each operation will be given on its own line. The first character of the line will be `D` for a $\text{Del}$ operation, `I` for an $\text{Ins}$ operation, or `E` marking the end of the program.
A $\text{Del}$ operation will have the `D` character, followed by a space, and then a single integer between $1$ and $10^{10}$, indicating the character position to delete. All characters after this deleted character will be shifted one position lower.
An $\text{Ins}$ operation will have the `I` character, followed by a space, and then a single integer between $1$ and $10^{10}$, indicating the location to insert the new character; all pre-existing characters with this index and higher will be shifted one position higher. Following this integer will be another space and then an uppercase alphabetic character that is the character to insert.
输出格式
If the two programs are identical, print `0` on a single line. Otherwise, print `1` on a single line.
样例输入 #1
D 1 D 2 E D 3 D 1 E
样例输出 #1
0
样例输入 #2
D 2 D 1 E D 1 D 2 E
样例输出 #2
1
样例输入 #3
I 1 X D 1 E E
样例输出 #3
0
样例输入 #4
I 14 B I 14 A E I 14 A I 15 B E
样例输出 #4
0
样例输入 #5
I 14 A I 15 B E I 14 B I 15 A E
样例输出 #5
1
来源
2017 Pacific Northwest Region Programming Contest