本文共 2363 字,大约阅读时间需要 7 分钟。
【题目】
SumTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4424 Accepted Submission(s): 1281Problem Description XXX is puzzled with the question below: 1, 2, 3, ..., n (1<=n<=400000) are placed in a line. There are m (1<=m<=1000) operations of two kinds. Operation 1: among the x-th number to the y-th number (inclusive), get the sum of the numbers which are co-prime with p( 1 <=p <= 400000). Operation 2: change the x-th number to c( 1 <=c <= 400000). For each operation, XXX will spend a lot of time to treat it. So he wants to ask you to help him.
Input There are several test cases. The first line in the input is an integer indicating the number of test cases. For each case, the first line begins with two integers --- the above mentioned n and m. Each the following m lines contains an operation. Operation 1 is in this format: "1 x y p". Operation 2 is in this format: "2 x c".
Output For each operation 1, output a single integer in one line representing the result.
Sample Input
1 3 3 2 2 3 1 1 3 4 1 2 3 6 Sample Output
7 0
|
【题意】
操作一查询并输出[a,b]中与p互质的数的总和,操作二更新pos位置的数值。
【思路】
与 非常相似,只不过这次是求和(相当于等差数列),再加上修改数值。
容斥定理的实现有三种做法:1.dfs 2.二进制 3.队列数组 。大致意思都是表示出每一种质因子的组成情况,奇数个相加,偶数个相减。
修改数值的话可以用map存一下修改的操作,最后把影响结果的操作拿出来处理一下即可。
【代码】
#include#include #include #include #include #include #include
转载地址:http://jyben.baihongyu.com/