#P9931. [NFLSPC #6] 挑战停机问题

[NFLSPC #6] 挑战停机问题

Background

As an OIer/XCPCer in the new era, you are no longer satisfied with challenging NP-complete problems. You want to challenge the undecidability in mathematics—the Turing halting problem.

Problem Description

Turing gives you a program. At the very beginning of the program, there is one and only one variable AA, with initial value 00. The program has nn lines, numbered 1n1 \sim n. Each line is one of the following forms:

  • A a: Set AA+aA \gets A + a, then execute the next line.
  • G x: Execute line xx.
  • I l r x y: If A[l,r]A \in [l, r], execute line xx; otherwise, execute line yy.
  • E: Terminate the program immediately.

It is guaranteed that the last line is E.

Turing wants you to determine whether this program will terminate when executed starting from line 1. To further test whether you can really decide the halting problem (or you are just pretending?), Turing also requires you to output the final value of AA. If the program does not terminate and there does not exist a moment after which AA no longer changes, output @Turing ?.

Input Format

This problem contains multiple test cases. The first line contains a positive integer TT indicating the number of test cases. For each test case:

  • The first line contains an integer nn, indicating the number of lines in the program.
  • The next nn lines describe the program.

Output Format

For each test case, output two lines:

  • The first line outputs a string Yes or No, indicating whether the program will terminate.
  • The second line outputs an integer A0A_{0} or the string @Turing ?, indicating the final value of AA.
3
5
I 1 7 1 3
G 4
A 2
G 2
E
6
A 2
I 2 3 5 1
E
G 4
A 1
E
4
A 1
G 1
E
E

No
2
Yes
3
No
@Turing ?

Hint

For all testdata, 1T10001 \leq T \leq 1000, 1n,n1051 \leq n, \sum n \leq 10^5, 1a1091 \leq a \leq 10^9, 0lr1090 \leq l \leq r \leq 10^9, 1x,yn1 \leq x, y \leq n. It is guaranteed that all numbers in the input are integers.

  • Subtask 1 (15 points): There are no I statements.
  • Subtask 2 (20 points): r100r \leq 100.
  • Subtask 3 (40 points): maxr105\sum \max r \leq 10^5.
  • Subtask 4 (25 points): No special constraints.

Source: NFLSPC #6 G by chenxia25

Translated by ChatGPT 5