{"trustable":true,"sections":[{"title":"题目描述","value":{"format":"MD","content":"**原题来自:AHOI 2009**\r\n\r\n老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成。\r\n\r\n有长为 $n$ 的数列,不妨设为 $a_1,a_2,\\cdots ,a_n$。有如下三种操作形式:\r\n+ 把数列中的一段数全部乘一个值;\r\n+ 把数列中的一段数全部加一个值;\r\n+ 询问数列中的一段数的和,由于答案可能很大,你只需输出这个数模 $P$ 的值。"}},{"title":"输入格式","value":{"format":"MD","content":"第一行两个整数 $n$ 和 $P$;\r\n\r\n第二行含有 $n$ 个非负整数,从左到右依次为 $a_1,a_2,\\cdots ,a_n$;\r\n\r\n第三行有一个整数 $M$,表示操作总数;\r\n\r\n从第四行开始每行描述一个操作,输入的操作有以下三种形式:\r\n+ 操作 $1$:`1 t g c`,表示把所有满足 $t\\le i\\le g$ 的 $a_i$ 改为 $a_i\\times c$;\r\n+ 操作 $2$:`2 t g c`,表示把所有满足 $t\\le i\\le g$ 的 $a_i$ 改为 $a_i+c$; \r\n+ 操作 $3$:`3 t g`,询问所有满足 $t\\le i\\le g$ 的 $a_i$ 的和模 $P$ 的值。\r\n\r\n同一行相邻两数之间用一个空格隔开,每行开头和末尾没有多余空格。"}},{"title":"输出格式","value":{"format":"MD","content":"对每个操作 $3$,按照它在输入中出现的顺序,依次输出一行一个整数表示询问结果。"}},{"title":"样例","value":{"format":"MD","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e7 43\n1 2 3 4 5 6 7\n5\n1 2 5 5\n3 2 4\n2 3 7 9\n3 1 3\n3 4 7\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\n35\n8\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n初始时数列为 $\\{1,2,3,4,5,6,7\\}$;\n\n经过第 $1$ 次操作后,数列为 $\\{1,10,15,20,25,6,7\\}$;\n\n对第 $2$ 次操作,和为 $10+15+20\u003d45$,模 $43$ 的结果是 $2$;\n\n经过第 $3$ 次操作后,数列为 $\\{1,10,24,29,34,15,16\\}$;\n\n对第 $4$ 次操作,和为 $1+10+24\u003d35$,模 $43$ 的结果是 $35$;\n\n对第 $5$ 次操作,和为 $29+34+15+16\u003d94$,模 $43$ 的结果是 $8$。"}},{"title":"数据范围与提示","value":{"format":"MD","content":"对于全部测试数据,$1\\le t\\le g\\le n,0\\le c,a_i\\le 10^9,1\\le P\\le 10^9+7$。\n\n测试数据规模如下表所示:\n\n| 数据编号 | $1$ | $2,3$ | $4$ | $5$ | $6$ | $7$ | $8$ | $9,10$ |\n| :------: | :--: | :----: | :----: | :------------: | :------------: | :------------: | :------------: | :----: |\n| $n\u003d$ | $10$ | $10^3$ | $10^4$ | $6\\times 10^4$ | $7\\times 10^4$ | $8\\times 10^4$ | $9\\times 10^4$ | $10^5$ |\n| $M\u003d$ | $10$ | $10^3$ | $10^4$ | $6\\times 10^4$ | $7\\times 10^4$ | $8\\times 10^4$ | $9\\times 10^4$ | $10^5$ |\n\n"}}]}