#P4546. [THUWC 2017] 在美妙的数学王国中畅游

[THUWC 2017] 在美妙的数学王国中畅游

Description

The underachiever Xiao R (pinyin) was tortured by university mathematics courses to the point of being unable to take care of himself. His calculus score was once the lowest among all the courses he took in the classroom. However, one of his roommates surnamed Chen could easily get full marks in math exams. To improve his math grades, one night (in his sleep), he arrived at the Kingdom of Mathematics.

In the Kingdom of Mathematics, everyone’s IQ is represented by a real number in [0,1] [0,1]. There are nn cities numbered from 0n10 \sim n-1, connected by several magic bridges. At the center of each city there is a magic orb, and inside each magic orb lies a math problem.

After solving this problem, everyone will receive a score in [0,1][0,1]. A problem can be represented by a function f(x)f(x). If a person’s IQ is xx, then after solving this problem he will receive f(x)f(x) points. There are three forms:

  • Sine function $f(x)=\sin(a x + b)\ (a \in [0,1], b \in [0,\pi],a+b\in[0,\pi])$.
  • Exponential function $f(x)=\text e^{ax+b}\ (a\in [-1,1], b\in [-2,0], a+b\in [-2,0])$.
  • Linear function $f(x) = ax + b\ (a\in [-1,1],b\in[0,1],a+b\in [0,1])$.

The magic bridges in the Kingdom of Mathematics change over time. Sometimes a magic bridge disappears, and sometimes a magic bridge appears. However, at any moment, there exists at most one simple path connecting any two cities (i.e., all cities form a forest). Initially, there are no magic bridges in the Kingdom of Mathematics.

King Lagrange of the Kingdom of Mathematics is happy to teach Xiao R (pinyin) math, but only if Xiao R first answers the king’s questions. These questions have the same form: for a person with IQ xx traveling from city uu to city vv (i.e., passing through all cities on the path uvu \to v, including uu and vv) and solving all the problems in those cities, what is the sum of all his scores.

Input Format

The first line contains two positive integers n,mn, m and a string typetype. They indicate that there are nn cities in the Kingdom of Mathematics, mm events occur, and the type of this testdata is typetype.

The string typetype is provided to help you obtain partial scores more easily; you may not need to use it. Its meaning is explained in Constraints and Assumptions.

The next nn lines describe, for each city ii, the function inside its magic orb in the initial state. One integer ff denotes the type of function, and two real numbers a,ba, b denote the parameters. If

  • f=1f=1, then the function is f(x)=sin(ax+b)f(x)=\sin(ax+b).
  • f=2f=2, then the function is f(x)=eax+bf(x)=\text e^{ax+b}.
  • f=3f=3, then the function is f(x)=ax+bf(x)=ax+b.

The next mm lines each describe an event, of one of four types.

  • appear u v means a magic bridge appears between cities uu and vv. It is guaranteed that before adding the bridge, uu and vv are not reachable from each other.
  • disappear u v means the magic bridge between uu and vv disappears. It is guaranteed that this magic bridge exists.
  • magic c f a b means the magic orb in city cc changes to a function of type ff with parameters a,ba, b.
  • travel u v x asks: for a person with IQ xx traveling from city uu to city vv, what is the sum of his scores. If uu cannot reach vv, output a single line containing the string unreachable.

Output Format

For each query, output one line with a real number representing the total score.

3 7 C1
1 1 0
3 0.5 0.5
3 -0.5 0.7
appear 0 1
travel 0 1 0.3
appear 0 2
travel 1 2 0.5
disappear 0 1
appear 1 2
travel 1 2 0.5
9.45520207e-001
1.67942554e+000
1.20000000e+000

Hint

Constraints and Assumptions.
For 100%100\% of the data, 1n105,1m2×1051\le n\le 10^5, 1\le m \le 2 \times 10^5.

There are 20 testdata points, each worth 5 points.

测试点 nn mm 数据类型
11 100\leq 100 200\leq 200 C1
252 \sim 5 105\leq 10^5 2×105\leq 2 \times 10^5 A0
66 B0
787 \sim 8 D0
9149 \sim 14 A1
151715 \sim 17 C1
182018 \sim 20 D1

Meaning of data types:

  • A: There is no disappear event, and in all appear events, u=v1u = v - 1.

  • B: There is no disappear event.

  • C: The total number of cities traversed over all travel events is 5×106\le 5 \times 10^6 (pairs that are unreachable are not counted).

  • D: No further restrictions.

  • 0: In all travel events, x=1x=1 (i.e., everyone’s IQ is 11).

  • 1: No restriction.

Scoring criteria.

If your answer differs from the standard answer by a relative error within 10710^{-7} or an absolute error within 10710^{-7}, it is considered correct.

You will receive full score only if all your answers are correct; otherwise, you receive 0 points.

Please pay attention to the output format: print one answer per line, and each line must be either unreachable or a real number (scientific notation is recommended). Each line must not exceed 50 characters. Incorrect output format will result in 0 points.

Xiao R Teaches You Math.

If the nn-th derivative of a function f(x)f(x) is continuous on the interval [a,b][a,b], then by applying the Lagrange mean value theorem nn times to f(x)f(x) at x0 (x0[a,b])x_0 \ (x_0\in[a,b]), we obtain the Taylor expansion with Lagrange remainder

$$f(x)=\sum_{k=0}^{n-1}\frac{f^{(k)}(x_0)(x-x_0)^k}{k!}+\frac{f^{(n)}(\xi)(x-x_0)^n}{n!},x\in[a,b]$$

where, when x>x0x>x_0, ξ[x0,x]\xi\in[x_0,x]. When x<x0x<x_0, ξ[x,x0]\xi\in[x,x_0].

f(n)f^{(n)} denotes the nn-th derivative of the function ff.

Translated by ChatGPT 5