CF1634F.Fibonacci Additions

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One of my most productive days was throwing away 1,000 lines of code.

— Ken Thompson

Fibonacci addition is an operation on an array XX of integers, parametrized by indices ll and rr. Fibonacci addition increases XlX_l by F1F_1, increases Xl+1X_{l + 1} by F2F_2, and so on up to XrX_r which is increased by Fr−l+1F_{r - l + 1}.

FiF_i denotes the ii-th Fibonacci number (F1=1F_1 = 1, F2=1F_2 = 1, Fi=Fi−1+Fi−2F_{i} = F_{i - 1} + F_{i - 2} for i>2i \gt 2), and all operations are performed modulo MODMOD.

You are given two arrays AA and BB of the same length. We will ask you to perform several Fibonacci additions on these arrays with different parameters, and after each operation you have to report whether arrays AA and BB are equal modulo MODMOD.

我最有成效的一天之一,是删掉了 1000 行代码。

— 肯·汤普森(Ken Thompson)

斐波那契加法(Fibonacci addition)是一种作用于整数数组 XX 的运算,由下标 ll 和 rr 参数化。该运算将 XlX_l 增加 F1F_1,将 Xl+1X_{l + 1} 增加 F2F_2,依此类推,直至将 XrX_r 增加 Fr−l+1F_{r - l + 1}。

其中 FiF_i 表示第 ii 个斐波那契数(定义为:F1=1F_1 = 1,F2=1F_2 = 1,且当 i>2i > 2 时 Fi=Fi−1+Fi−2F_i = F_{i - 1} + F_{i - 2}),所有运算均在模 MODMOD 意义下进行。

给定两个等长的数组 AA 和 BB。我们将要求你对这两个数组执行若干次参数不同的斐波那契加法操作;每次操作后,你都需要报告数组 AA 与 BB 在模 MODMOD 意义下是否相等。

输入格式

The first line contains 3 numbers nn, qq and MODMOD (1≤n,q≤3⋅105,1≤MOD≤109+71 \le n, q \le 3\cdot 10^5, 1 \le MOD \le 10^9+7) — the length of the arrays, the number of operations, and the number modulo which all operations are performed.

The second line contains nn numbers — array AA (0≤Ai<MOD0 \le A_i \lt MOD).

The third line also contains nn numbers — array BB (0≤Bi<MOD0 \le B_i \lt MOD).

The next qq lines contain character cc and two numbers ll and rr (1≤l≤r≤n1 \le l \le r \le n) — operation parameters. If cc is "A", Fibonacci addition is to be performed on array AA, and if it is is "B", the operation is to be performed on BB.

第一行包含三个数字 nn、qq 和 MODMOD(1≤n,q≤3⋅1051 \le n, q \le 3\cdot 10^5,1≤MOD≤109+71 \le MOD \le 10^9+7)——分别表示数组长度、操作次数,以及所有运算所取模的模数。

第二行包含 nn 个数字——数组 AA(0≤Ai<MOD0 \le A_i \lt MOD)。

第三行也包含 nn 个数字——数组 BB(0≤Bi<MOD0 \le B_i \lt MOD)。

接下来的 qq 行每行包含一个字符 cc 和两个数字 ll、rr(1≤l≤r≤n1 \le l \le r \le n)——表示操作参数。若 cc 为 "A",则对数组 AA 执行斐波那契加法;若 cc 为 "B",则对数组 BB 执行该操作。

输出格式

After each operation, print "YES" (without quotes) if the arrays are equal and "NO" otherwise. Letter case does not matter.

每次操作后,如果两个数组相等,则输出 "YES"(不带引号),否则输出 "NO"。字母大小写不敏感。

输入输出样例

  • 输入#1

    3 5 3
    2 2 1
    0 0 0
    A 1 3
    A 1 3
    B 1 1
    B 2 2
    A 3 3

    输出#1

    YES
    NO
    NO
    NO
    YES
  • 输入#2

    5 3 10
    2 5 0 3 5
    3 5 8 2 5
    B 2 3
    B 3 4
    A 1 2

    输出#2

    NO
    NO
    YES

说明/提示

Explanation of the test from the condition:

  • Initially A=[2,2,1]A=[2,2,1], B=[0,0,0]B=[0,0,0].
  • After operation "A 1 3": A=[0,0,0]A=[0,0,0], B=[0,0,0]B=[0,0,0] (addition is modulo 3).
  • After operation "A 1 3": A=[1,1,2]A=[1,1,2], B=[0,0,0]B=[0,0,0].
  • After operation "B 1 1": A=[1,1,2]A=[1,1,2], B=[1,0,0]B=[1,0,0].
  • After operation "B 2 2": A=[1,1,2]A=[1,1,2], B=[1,1,0]B=[1,1,0].
  • After operation "A 3 3": A=[1,1,0]A=[1,1,0], B=[1,1,0]B=[1,1,0].

根据题目的条件对测试样例进行解释:

  • 初始时 A=[2,2,1]A=[2,2,1],B=[0,0,0]B=[0,0,0]。
  • 执行操作 “A 1 3” 后:A=[0,0,0]A=[0,0,0],B=[0,0,0]B=[0,0,0](加法运算在模 3 意义下进行)。
  • 执行操作 “A 1 3” 后:A=[1,1,2]A=[1,1,2],B=[0,0,0]B=[0,0,0]。
  • 执行操作 “B 1 1” 后:A=[1,1,2]A=[1,1,2],B=[1,0,0]B=[1,0,0]。
  • 执行操作 “B 2 2” 后:A=[1,1,2]A=[1,1,2],B=[1,1,0]B=[1,1,0]。
  • 执行操作 “A 3 3” 后:A=[1,1,0]A=[1,1,0],B=[1,1,0]B=[1,1,0]。

输入解题思路,AI测评打分。不知道怎么写?

首页