CF1109E.Sasha and a Very Easy Test

省选/NOI-

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

Egor likes math, and not so long ago he got the highest degree of recognition in the math community — Egor became a red mathematician. In this regard, Sasha decided to congratulate Egor and give him a math test as a present. This test contains an array aa of integers of length nn and exactly qq queries. Queries were of three types:

  1. "1 l r x" — multiply each number on the range from ll to rr by xx.
  2. "2 p x" — divide the number at the position pp by xx (divisibility guaranteed).
  3. "3 l r" — find the sum of all elements on the range from ll to rr.

The sum can be big, so Sasha asked Egor to calculate the sum modulo some integer modmod.

But since Egor is a red mathematician, he doesn't have enough time to solve such easy tasks, at the same time he doesn't want to anger Sasha, that's why he asked you to help and to find answers for all queries of the 33-rd type.

叶戈尔热爱数学,不久前他获得了数学界最高级别的认可——叶戈尔成为了一名“红色数学家”。为此,萨沙决定向叶戈尔表示祝贺,并送给他一份数学测试作为礼物。该测试包含一个长度为 nn 的整数数组 aa,以及恰好 qq 个查询。查询分为以下三种类型:

  1. “1 l r x” —— 将区间 [l,r][l, r] 内的每个数乘以 xx;
  2. “2 p x” —— 将位置 pp 处的数除以 xx(题目保证整除);
  3. “3 l r” —— 求区间 [l,r][l, r] 内所有元素的和。

由于和可能很大,萨沙要求叶戈尔将结果对某个整数 modmod 取模。

但身为一名“红色数学家”,叶戈尔没有足够时间来解决如此简单的任务;与此同时,他又不想惹恼萨沙。因此,他请你帮忙,计算并输出所有第 33 类查询的答案。

输入格式

The first line contains two integers nn and modmod (1≤n≤1051 \le n \le 10^5, 2≤mod≤109+92 \le mod \le 10^9 + 9) — the size of the array and the number modmod.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1051 \le a_i \le 10^5) — the array itself.

The third line contains one integer qq(1≤q≤1051 \le q \le 10^5) — the number of queries.

Next qq lines satisfy one of the following formats:

  • 1 l r x (1≤l≤r≤n1 \le l \le r \le n, 1≤x≤1051 \le x \le 10^5), means that you must multiply each number on the range from ll to rr by xx.
  • 2 p x (1≤p≤n1 \le p \le n, 1≤x≤1051 \le x \le 10^5), means that you must divide number at the position pp by xx (divisibility guaranteed).
  • 3 l r (1≤l≤r≤n1 \le l \le r \le n), means that you must find the sum of elements on the range from ll to rr.

It is guaranteed that there is at least one query of the 33-rd type.

第一行包含两个整数 nn 和 modmod(1≤n≤1051 \le n \le 10^5,2≤mod≤109+92 \le mod \le 10^9 + 9)——分别表示数组的大小和模数 modmod。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1051 \le a_i \le 10^5)——即该数组本身。

第三行包含一个整数 qq(1≤q≤1051 \le q \le 10^5)——表示查询的数量。

接下来的 qq 行中,每行属于以下格式之一:

  • 1 l r x(1≤l≤r≤n1 \le l \le r \le n,1≤x≤1051 \le x \le 10^5),表示将区间 [l,r][l, r] 内的每个数乘以 xx。
  • 2 p x(1≤p≤n1 \le p \le n,1≤x≤1051 \le x \le 10^5),表示将位置 pp 处的数除以 xx(保证整除)。
  • 3 l r(1≤l≤r≤n1 \le l \le r \le n),表示求区间 [l,r][l, r] 内所有元素的和。

保证至少存在一个类型为 33 的查询。

输出格式

For each query of the 33-rd type print the answer on a new line modulo modmod.

对于每个第 3 类查询,在新的一行输出答案,对 modmod 取模。

输入输出样例

  • 输入#1

    5 100
    4 1 2 3 5
    5
    3 1 5
    1 2 3 6
    3 1 2
    1 1 5 1
    3 2 4

    输出#1

    15
    10
    21
  • 输入#2

    5 2
    4 1 2 3 5
    7
    3 1 5
    1 2 3 6
    3 1 2
    1 1 5 1
    3 2 4
    2 3 4
    3 3 4

    输出#2

    1
    0
    1
    0
  • 输入#3

    5 2100
    1 2 3 4 5
    10
    1 1 3 12
    1 1 5 10
    2 5 50
    3 2 4
    1 4 4 28
    2 4 7
    3 1 2
    3 3 4
    2 3 3
    3 1 5

    输出#3

    640
    360
    520
    641

说明/提示

The first example:

Inital array is [4,1,2,3,5][4, 1, 2, 3, 5]

  • In the first query, you must calculate the sum of the whole array, it's equal to (4+1+2+3+5) mod 100=15 mod 100=15(4 + 1 + 2 + 3 + 5) \bmod 100 = 15 \bmod 100 = 15
  • In the second query, you must multiply each number on the range from 22 to 33 by 66. The resulting array will be [4,6,12,3,5][4, 6, 12, 3, 5]
  • In the third query, you must calculate the sum on the range from 11 to 22, it's equal to (4+6) mod 100=10 mod 100=10(4 + 6) \bmod 100 = 10 \bmod 100 = 10
  • In the fourth query, you must multiply each number on the range from 11 to 55 by 11. Multiplication by 11 doesn't affect the array.
  • In the fifth query, you must calculate the sum on the range from 22 to 44, it's equal to (6+12+3) mod 100=21 mod 100=21(6 + 12 + 3) \bmod 100 = 21 \bmod 100 = 21

The second example:

Inital array is [4,1,2,3,5][4, 1, 2, 3, 5]

  • In the first query, you must calculate the sum of the whole array, it's equal to (4+1+2+3+5) mod 2=15 mod 2=1(4 + 1 + 2 + 3 + 5) \bmod 2 = 15 \bmod 2 = 1
  • In the second query, you must multiply each number on the range from 22 to 33 by 66. The resulting array will be [4,6,12,3,5][4, 6, 12, 3, 5]
  • In the third query, you must calculate the sum on the range from 11 to 22, it's equal to (4+6) mod 2=10 mod 2=0(4 + 6) \bmod 2 = 10 \bmod 2 = 0
  • In the fourth query, you must multiply each number on the range from 11 to 55 by 11. Multiplication by 11 doesn't affect the array.
  • In the fifth query, you must calculate the sum on the range from 22 to 44, it's equal to (6+12+3) mod 2=21 mod 2=1(6 + 12 + 3) \bmod 2 = 21 \bmod 2 = 1
  • In the sixth query, you must divide number at the position 33 by 44. 124=3\frac{12}{4}=3, so the array will be [4,6,3,3,5][4, 6, 3, 3, 5].
  • In the seventh, query you must calculate the sum on the range form 33 to 44, it's equal to (3+3) mod 2=6 mod 2=0(3 + 3) \bmod 2 = 6 \bmod 2 = 0

第一个例子:

初始数组为 [4,1,2,3,5][4, 1, 2, 3, 5]

  • 在第一个查询中,你需要计算整个数组的和,结果为 (4+1+2+3+5) mod 100=15 mod 100=15(4 + 1 + 2 + 3 + 5) \bmod 100 = 15 \bmod 100 = 15
  • 在第二个查询中,你需要将区间 [2,3][2, 3] 内的每个数乘以 66。得到的新数组为 [4,6,12,3,5][4, 6, 12, 3, 5]
  • 在第三个查询中,你需要计算区间 [1,2][1, 2] 内元素的和,结果为 (4+6) mod 100=10 mod 100=10(4 + 6) \bmod 100 = 10 \bmod 100 = 10
  • 在第四个查询中,你需要将区间 [1,5][1, 5] 内的每个数乘以 11。乘以 11 不改变数组。
  • 在第五个查询中,你需要计算区间 [2,4][2, 4] 内元素的和,结果为 (6+12+3) mod 100=21 mod 100=21(6 + 12 + 3) \bmod 100 = 21 \bmod 100 = 21

第二个例子:

初始数组为 [4,1,2,3,5][4, 1, 2, 3, 5]

  • 在第一个查询中,你需要计算整个数组的和,结果为 (4+1+2+3+5) mod 2=15 mod 2=1(4 + 1 + 2 + 3 + 5) \bmod 2 = 15 \bmod 2 = 1
  • 在第二个查询中,你需要将区间 [2,3][2, 3] 内的每个数乘以 66。得到的新数组为 [4,6,12,3,5][4, 6, 12, 3, 5]
  • 在第三个查询中,你需要计算区间 [1,2][1, 2] 内元素的和,结果为 (4+6) mod 2=10 mod 2=0(4 + 6) \bmod 2 = 10 \bmod 2 = 0
  • 在第四个查询中,你需要将区间 [1,5][1, 5] 内的每个数乘以 11。乘以 11 不改变数组。
  • 在第五个查询中,你需要计算区间 [2,4][2, 4] 内元素的和,结果为 (6+12+3) mod 2=21 mod 2=1(6 + 12 + 3) \bmod 2 = 21 \bmod 2 = 1
  • 在第六个查询中,你需要将位置 33 处的数除以 44。124=3\frac{12}{4}=3,因此数组变为 [4,6,3,3,5][4, 6, 3, 3, 5]。
  • 在第七个查询中,你需要计算区间 [3,4][3, 4] 内元素的和,结果为 (3+3) mod 2=6 mod 2=0(3 + 3) \bmod 2 = 6 \bmod 2 = 0

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

首页