CF1097F.Alex and a TV Show
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alex decided to try his luck in TV shows. He once went to the quiz named "What's That Word?!". After perfectly answering the questions "How is a pseudonym commonly referred to in the Internet?" ("Um... a nick?"), "After which famous inventor we name the unit of the magnetic field strength?" ("Um... Nikola Tesla?") and "Which rock band performs "How You Remind Me"?" ("Um... Nickelback?"), he decided to apply to a little bit more difficult TV show: "What's in This Multiset?!".
The rules of this TV show are as follows: there are n multisets numbered from 1 to n. Each of them is initially empty. Then, q events happen; each of them is in one of the four possible types:
- 1 x v — set the x-th multiset to a singleton v.
- 2 x y z — set the x-th multiset to a union of the y-th and the z-th multiset. For example: 1,3∪1,4,4=1,1,3,4,4.
- 3 x y z — set the x-th multiset to a product of the y-th and the z-th multiset. The product A×B of two multisets A, B is defined as gcd(a,b)∣a∈A,b∈B, where gcd(p,q) is the greatest common divisor of p and q. For example: 2,2,3×1,4,6=1,2,2,1,2,2,1,1,3.
- 4 x v — the participant is asked how many times number v occurs in the x-th multiset. As the quiz turned out to be too hard in the past, participants should now give the answers modulo 2 only.
Note, that x, y and z described above are not necessarily different. In events of types 2 and 3, the sum or the product is computed first, and then the assignment is performed.
Alex is confused by the complicated rules of the show. Can you help him answer the requests of the 4-th type?
亚历克斯决定尝试参加电视节目。他曾经参加过一档名为“这是什么单词?!”的问答节目。在完美回答了以下问题后——“网络上通常将笔名称为什么?”(“呃……昵称?”)、“磁场强度的单位以哪位著名发明家的名字命名?”(“呃……尼古拉·特斯拉?”)以及“哪支摇滚乐队演唱了《How You Remind Me》?”(“呃……Nickelback?”)——他决定挑战一档难度稍高的电视节目:“这个多重集里有什么?!”
该节目的规则如下:共有 n 个编号从 1 到 n 的多重集,每个多重集初始均为空。随后发生 q 个事件,每个事件属于以下四种类型之一:
1 x v—— 将第 x 个多重集设为单元素多重集 {v}。2 x y z—— 将第 x 个多重集设为第 y 个与第 z 个多重集的并集。例如:{1,3}∪{1,4,4}={1,1,3,4,4}。3 x y z—— 将第 x 个多重集设为第 y 个与第 z 个多重集的乘积。两个多重集 A、B 的乘积 A×B 定义为 {gcd(a,b)∣a∈A,b∈B},其中 gcd(p,q) 表示 p 与 q 的最大公约数。例如:{2,2,3}×{1,4,6}={1,2,2,1,2,2,1,1,3}。4 x v—— 参赛者需回答数字 v 在第 x 个多重集中出现的次数。由于过去该问答环节难度过高,现参赛者只需给出答案对 2 取模的结果。
注意,上述描述中的 x、y 和 z 不一定互不相同。对于类型 2 和 3 的事件,先计算并集或乘积,再执行赋值操作。
亚历克斯被这复杂的节目规则弄糊涂了。你能帮他回答所有类型 4 的询问吗?
输入格式
The first line contains two integers n and q (1≤n≤105, 1≤q≤106) — the number of multisets and the number of events.
Each of the following q lines describes next event in the format given in statement. It's guaranteed that 1≤x,y,z≤n and 1≤v≤7000 always holds.
It's guaranteed that there will be at least one event of the 4-th type.
第一行包含两个整数 n 和 q(1≤n≤105,1≤q≤106)—— 分别表示多重集的数量和事件的数量。
接下来的 q 行每行描述一个事件,格式如题目陈述中所给。保证始终满足 1≤x,y,z≤n 且 1≤v≤7000。
保证至少存在一个类型为 4 的事件。
输出格式
Print a string which consists of digits 0 and 1 only, and has length equal to the number of events of the 4-th type. The i-th digit of the string should be equal to the answer for the i-th query of the 4-th type.
输出一个仅由数字 0 和 1 组成的字符串,其长度等于第 4 类事件的数量。该字符串的第 i 位数字应等于第 i 个第 4 类查询的答案。
输入输出样例
输入#1
4 13 1 1 1 1 2 4 1 3 6 4 4 4 1 4 4 2 2 1 2 2 3 3 4 4 4 4 3 2 2 3 4 2 1 4 2 2 4 2 3 4 2 4
输出#1
010101
说明/提示
Here is how the multisets look in the example test after each of the events; i is the number of queries processed so far:

以下是示例测试中每次事件后多重集的样子;i 表示目前已处理的查询数量:

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