#3221. Filters

0

Filters

Filters

题目描述

给定整数序列 A=(a1,a2,…,aN)A = (a_1, a_2, \dots, a_N)、T=(t1,t2,…,tN)T = (t_1, t_2, \dots, t_N) 和 X=(x1,x2,…,xQ)X = (x_1, x_2, \dots, x_Q)。
令我们定义 NN 个函数 f1(x),f2(x),…,fN(x)f_1(x), f_2(x), \dots, f_N(x) 如下: $f_i(x) = \begin{cases} x + a_i & (t_i = 1)\\ \max(x, a_i) & (t_i = 2)\\ \min(x, a_i) & (t_i = 3)\\ \end{cases}$ 对于每个 i=1,2,…,Qi = 1, 2, \dots, Q,求 fN(…f2(f1(xi))… )f_N( \dots f_2(f_1(x_i)) \dots )。

输入格式

输入按照下述格式从标准输入给出: NN a1a_1 t1t_1 a2a_2 t2t_2 ⋮\vdots aNa_N tNt_N QQ x1x_1 x2x_2 ⋯\cdots xQx_Q

输出格式

输出 QQ 行。第 ii 行应包含 fN(…f2(f1(xi))… )f_N( \dots f_2(f_1(x_i)) \dots )。

3
-10 2
10 1
10 3
5
-15 -10 -5 0 5
0
0
5
10
10

提示

输入中的所有值均为整数。 1≤N≤2×1051 ≤ N ≤ 2 \times 10^5 1≤Q≤2×1051 ≤ Q ≤ 2 \times 10^5 ∣ai∣≤109|a_i| ≤ 10^9 1≤ti≤31 ≤ t_i ≤ 3 ∣xi∣≤109|x_i| ≤ 10^9我们有 $f_1(x) = \max(x, -10), f_2(x) = x + 10, f_3(x) = \min(x, 10)$,因此:

f3(f2(f1(−15)))=0f_3(f_2(f_1(-15))) = 0 f3(f2(f1(−10)))=0f_3(f_2(f_1(-10))) = 0 f3(f2(f1(−5)))=5f_3(f_2(f_1(-5))) = 5 f3(f2(f1(0)))=10f_3(f_2(f_1(0))) = 10 f3(f2(f1(5)))=10f_3(f_2(f_1(5))) = 10

标签: AtCoder|abc196E

来源

AtCoder|abc196E