编程介的小学生 2017-11-17 01:29 采纳率: 20.5%
浏览 628
已结题

About set

Problem Description
Today Zhanyl (sister Zhan as you know) receives a task about set operation. Although she is very good at this task,
but you know she is very lazy so that she wants you to help her write a program to complete this task. Surly
Zhanyl is able to solve this question, but you know, she is just lazy ...
Here is the problem, you are given n numbers, each number i has a value Ai, initially they are in different set.
Following there are m operations/querys.
The following is 5 possible kinds of oprations/querys:
1 u v: Union the set u belongs to and the set v belongs to.
2 u v: Delete u from its original set and add it to the set v belongs to.
3 u x: change the value of u to x. 1<=x<=109
4 u: query how many numbers you can choose most in set which u belongs to, so no three numbers can form a triangle.
5 u l r: query the gcd of the numbers between [l,r] in the set u belongs to, if there is no number between [l,r],you can suppose the answer is -1. 1<=l<=r<=109
Because Zhanyl is a good person, so she guarantee 1<=u,v<=n above.
You need to tell Zhanyl the answer to each query.

Input
The first line of the input is a single integer T which is the number of test cases.Then comes the T test cases .
For each test case, the first line contains two integer n and m, n is the number of set initially, m is the number
of operations/querys.
Following line contains n integers, A1, A2, ... , An, the value of i-th number.
Following m lines, each line is a operation or query.

Note that 1<=n,m<=105, 1<=Ai<=109

Output
For each case,output "Case #X:" in one line first, X is the case number starting from 1. Following you should output all the querys, each query a line.

Sample Input
1
5 5
1 2 3 4 5
1 2 4
5 2 1 5
2 1 4
3 2 3
4 2

Sample Output
Case #1:
2
3

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
    • ¥20 Python安装cvxpy库出问题
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥15 python天天向上类似问题,但没有清零
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
    • ¥15 C#调用python代码(python带有库)
    • ¥15 活动选择题。最多可以参加几个项目?
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题