Rikka with Phi

 Accepts: 5
 Submissions: 66
 Time Limit: 16000/8000 MS (Java/Others)
 Memory Limit: 131072/131072 K (Java/Others)
Problem Description

Rikka and Yuta are interested in Phi function (which is known as Euler's totient function).

Yuta gives Rikka an array A[1..n]A[1..n] of positive integers, then Yuta makes mm queries.

There are three types of queries:

1 \; l \; r1lr

Change A[i]A[i] into \varphi(A[i])φ(A[i]), for all i \in [l, r]i∈[l,r].

2 \; l \; r \; x2lrx

Change A[i]A[i] into xx, for all i \in [l, r]i∈[l,r].

3 \; l \; r3lr

Sum up A[i]A[i], for all i \in [l, r]i∈[l,r].

Help Rikka by computing the results of queries of type 3.

Input

The first line contains a number T(T \leq 100)T(T≤100) ——The number of the testcases. And there are no more than 2 testcases with n > 10 ^ 5n>10​5​​

For each testcase, the first line contains two numbers n,m(n \leq 3 \times 10^5, m \leq 3 \times 10^5)n,m(n≤3×10​5​​,m≤3×10​5​​)。

The second line contains nn numbers A[i]A[i]

Each of the next mm lines contains the description of the query.

It is guaranteed that 1 \leq A[i] \leq 10^71≤A[i]≤10​7​​ At any moment.

Output

For each query of type 3, print one number which represents the answer.

Sample Input
1
10 10
56 90 33 70 91 69 41 22 77 45
1 3 9
1 1 10
3 3 8
2 5 6 74
1 1 8
3 1 9
1 2 10
1 4 9
2 8 8 69
3 3 9
Sample Output
80
122
86
/*
BestCoder Round #73 (div.1)
hdu5634 Rikka with Phi
本来最开始用伸展树(主要是线段树不是很熟)的,但是中间有点问题,导致一直是TLE,于是乎
就去写线段树了
感觉对线段树的理解上有很多问题TAT
思路:先打个表然后用线段树(平衡树)去解决
主要是有same标记,sum和,欧拉
中间在将一个区间改变成欧拉时,如果中间遇到了区间的same,直接
修改这个标记就好的
hhh-2016-02-25 17:54:59
*/ #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;
typedef long long ll;
typedef long double ld; const int maxn = 300010;
ll euler[10000010] = {0};
void getEuler()
{
euler[1] = 1;
for(ll i =2 ; i <= 10000000; i++)
{
if(!euler[i])
{
for(ll j = i; j <= 10000000; j += i)
{
if(!euler[j])
euler[j] = j;
euler[j] = euler[j]/i*(i-1);
}
}
}
} struct node
{
int l,r;
ll sum,same;
} segtree[maxn<<2]; void push_up(int r)
{
int lson = r<<1,rson = (r<<1)|1;
segtree[r].sum = segtree[lson].sum + segtree[rson].sum;
if(segtree[lson].same == segtree[rson].same)
segtree[r].same = segtree[lson].same;
else
segtree[r].same = 0;
} void build(int i ,int l,int r)
{
segtree[i].l = l,segtree[i].r = r;
segtree[i].sum = segtree[i].same = 0;
if(l == r)
{
scanf("%I64d",&segtree[i].same);
segtree[i].sum = segtree[i].same;
return ;
}
int mid = (l+r)>>1;
build(i<<1,l,mid);
build((i<<1)|1,mid+1,r);
push_up(i);
} void push_down(int r)
{
int lson = r<<1,rson = (r<<1)|1;
if(segtree[r].same)
{
segtree[lson].same = segtree[r].same;
segtree[rson].same = segtree[r].same;
segtree[lson].sum = (ll)(segtree[lson].r - segtree[lson].l+1)*segtree[r].same;
segtree[rson].sum = (ll)(segtree[rson].r - segtree[rson].l+1)*segtree[r].same;
segtree[r].same = 0;
}
} void make_euler(int i,int l,int r)
{
//区间修改
if(segtree[i].r <= r && segtree[i].l >= l && segtree[i].same)
{
segtree[i].same = (ll)euler[segtree[i].same];
segtree[i].sum = segtree[i].same*(ll)(segtree[i].r-segtree[i].l+1);
return;
}
if(l == r) return ;
int mid = (segtree[i].r +segtree[i].l) >>1;
push_down(i);
if(l <= mid)
make_euler(i<<1,l,r);
if(r > mid)
make_euler((i<<1)|1,l,r);
push_up(i);
}
void make_same(int i,int l,int r,ll c)
{
if(segtree[i].r <= r && segtree[i].l >= l)
{
segtree[i].same = c;
segtree[i].sum = segtree[i].same*(ll)(segtree[i].r-segtree[i].l+1);
return;
}
int mid = (segtree[i].r +segtree[i].l) >>1;
push_down(i);
if(l <= mid)
make_same(i<<1,l,r,c);
if(r > mid)
make_same((i<<1)|1,l,r,c);
push_up(i);
} ll get_sum(int i,int l,int r)
{
int mid = (segtree[i].l + segtree[i].r) >> 1;
if(segtree[i].l >= l && segtree[i].r <= r)
{
return segtree[i].sum;
}
push_down(i);
ll ans = 0;
if(l <= mid) ans += get_sum(i<<1,l,r);
if(r > mid) ans += get_sum(i<<1|1,l,r);
push_up(i);
return ans;
} int main()
{
int T,n,m;
getEuler();
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
build(1,1,n);
for(int i =1; i <= m; i++)
{
int op,l,r;
ll c;
scanf("%d",&op);
if(op == 1)
{
scanf("%d%d",&l,&r);
make_euler(1,l,r);
//debug();
}
else if(op == 2)
{
scanf("%d%d%I64d",&l,&r,&c);
make_same(1,l,r,c);
// debug();
}
else if(op == 3)
{
scanf("%d%d",&l,&r);
printf("%I64d\n",get_sum(1,l,r));
}
}
}
return 0;
}

  

hdu5634 BestCoder Round #73 (div.1)的更多相关文章

  1. hdu5631 BestCoder Round #73 (div.2)

    Rikka with Graph  Accepts: 123  Submissions: 525  Time Limit: 2000/1000 MS (Java/Others)  Memory Lim ...

  2. hdu5630 BestCoder Round #73 (div.2)

    Rikka with Chess  Accepts: 393  Submissions: 548  Time Limit: 2000/1000 MS (Java/Others)  Memory Lim ...

  3. BestCoder Round #73 (div.2)

    1001 Rikka with Chess ans = n / 2 + m / 2 1002 Rikka with Graph 题意:n + 1条边,问减去至少一条使剩下的图连通的方案数. 分析:原来 ...

  4. BestCoder Round #73 (div.2)(hdu 5630)

    Rikka with Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  5. BestCoder Round #73 (div.2)1002/hdoj5631

    题意: 给出一张 nnn 个点 n+1n+1n+1 条边的无向图,你可以选择一些边(至少一条)删除. 分析: 一张n个点图,至少n-1条边才能保证联通 所以可以知道每次可以删去1条边或者两条边 一开始 ...

  6. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  7. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  8. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  9. hdu5635 BestCoder Round #74 (div.2)

    LCP Array  Accepts: 131  Submissions: 1352  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 13 ...

随机推荐

  1. DML数据操作语言之查询(二)

    当我们查询出了N条记录之后 ,我们知道一共是几条记录,或者这些记录某一字段(列值)的最大值,最小值,平均值等,就可以使用聚合函数. 1.聚合函数 聚合函数会将null 排除在外.但是count(*)例 ...

  2. 国内maven仓库地址 || 某个pom或者jar找不到的解决方法

    解决方法 建议在maven仓库中新建settings.xml,然后把如下内容粘贴进去即可.也可以找到maven的安装目录中的conf/settings.xml,把如下的mirrors节复制到对应部分. ...

  3. Java面试题合集(一)

    接下来几篇文章准备系统整理一下有关Java的面试题,分为基础篇,javaweb篇,框架篇,数据库篇,多线程篇,并发篇,算法篇等等,陆续更新中. 其他方面如前端后端等等的面试题也在整理中,都会有的. 所 ...

  4. 剑指offer-数组中出现次数超过一半的数字

    题目描述 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2. ...

  5. PHP常见排序算法

    $a = [1, 3, 5, 2, 4, 6, 12, 60, 45, 10, 32];$len = count($a);$num=0;/* * 冒泡排序 * 原理:不停的对相邻两个数进行比较,直到最 ...

  6. 用javascript做别踩白块游戏2

    这一次做一个好一点的,要求黑块自动下落,且速度逐渐加快 <!DOCTYPE html> <html> <head> <!-- 禁用缩放功能 --> &l ...

  7. Extensions in UWP Community Toolkit - FrameworkElement Extensions

    概述 UWP Community Toolkit Extensions 中有一个为FrameworkElement 提供的扩展 - FrameworkElement Extensions,本篇我们结合 ...

  8. 新概念英语(1-9)How is Ema?

    A:Hello Helen. B:Hi Steven. A:How are you today? B:I'm very well, thank you. And you? A:I'm fine tha ...

  9. JSON(五)——同步请求中使用JSON格式字符串进行交互(不太常见的用法)

    在同步请求中使用JSON格式进行数据交互的场景并不多,同步请求是浏览器直接与服务器进行数据交互的大多是用jsp的标签jstl和el表达式对请求中的数据进行数据的渲染.我也是在一次开发中要从其它服务器提 ...

  10. 翻译:JVM虚拟机规范1.7中的运行时常量池部分(三)

    4.4.7. The CONSTANT_Utf8_info Structure The CONSTANT_Utf8_info structure is used to represent consta ...