HDU5634 Rikka with Phi 线段树
// HDU5634 Rikka with Phi 线段树
// 思路:操作1的时候,判断一下当前区间是不是每个数都相等,在每个数相等的区间上操作。相当于lazy,不必更新到底。 #include <bits/stdc++.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int MOD = 1e9+;
#define LL long long
double const pi = acos(-);
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
const int MAXM=1e7+;
LL euler[];
int a[N];
void Geteuler()
{
memset(euler, , sizeof(euler));
euler[] = ;
for(LL i = ; i < MAXM; i++) if(!euler[i])
for(LL j = i; j < MAXM; j += i){
if(!euler[j]) euler[j] = j;
euler[j] = euler[j] / i * (i-);
}
} struct tree{
int l,r;
LL sum,lazy;
}t[N<<]; void pushup(int rt){
t[rt].sum=t[rt<<].sum+t[rt<<|].sum;
if(t[rt<<].lazy==t[rt<<|].lazy) t[rt].lazy=t[rt<<].lazy;
else t[rt].lazy=;
} void pushdown(int rt){
if(t[rt].lazy){
t[rt<<].lazy=t[rt<<|].lazy=t[rt].lazy;
t[rt<<].sum=(t[rt<<].r-t[rt<<].l+)*t[rt<<].lazy;
t[rt<<|].sum=(t[rt<<|].r-t[rt<<|].l+)*t[rt<<|].lazy;
t[rt].lazy=;
}
}
void build(int rt,int x,int y){
t[rt].l=x;
t[rt].r=y;
if(x==y){
t[rt].sum=a[x];
t[rt].lazy=a[x];
return;
}
int mid=(x+y)>>;
build(rt<<,x,mid);
build(rt<<|,mid+,y);
pushup(rt);
} void update1(int rt,int x,int y){
if(t[rt].lazy&&t[rt].l==x&&t[rt].r==y){
t[rt].sum=(t[rt].r-t[rt].l+)*euler[t[rt].lazy];
t[rt].lazy=euler[t[rt].lazy];
return;
}
pushdown(rt);
int mid=(t[rt].l+t[rt].r)>>;
if(y<=mid) update1(rt<<,x,y);
else if(x>mid) update1(rt<<|,x,y);
else {
update1(rt<<,x,mid);
update1(rt<<|,mid+,y);
}
pushup(rt);
} void update2(int rt,int x,int y,int z){
if(t[rt].l==x&&t[rt].r==y){
t[rt].lazy=z;
t[rt].sum=1LL*z*(t[rt].r-t[rt].l+);
return;
}
pushdown(rt);
int mid=(t[rt].l+t[rt].r)>>;
if(y<=mid) update2(rt<<,x,y,z);
else if(x>mid) update2(rt<<|,x,y,z);
else {
update2(rt<<,x,mid,z);
update2(rt<<|,mid+,y,z);
}
pushup(rt);
} LL query(int rt,int x,int y){
if(t[rt].l==x&&t[rt].r==y){
return t[rt].sum;
}
pushdown(rt);
int mid=(t[rt].l+t[rt].r)>>;
if(y<=mid) return query(rt<<,x,y);
else if(x>mid) return query(rt<<|,x,y);
else{
return query(rt<<,x,mid)+query(rt<<|,mid+,y);
}
}
int main(){
// fre();
Geteuler();
int T;
scanf("%d",&T);
while(T--){
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
build(,,n);
while(m--){
int op,x,y,z;
scanf("%d%d%d",&op,&x,&y);
if(op==) update1(,x,y);
else if(op==) {
scanf("%d",&z);
update2(,x,y,z);
}
else {
// cout<<"sdf"<<endl;
LL ans=query(,x,y);
printf("%I64d\n",ans);
}
}
}
return ;
}
HDU5634 Rikka with Phi 线段树的更多相关文章
- HDU 5634 Rikka with Phi 线段树
题意:bc round 73 div1 D 中文题面 分析:注意到10^7之内的数最多phi O(log(n))次就会变成1, 因此可以考虑把一段相同的不为1的数缩成一个点,用平衡树来维护. 每次求p ...
- Rikka with Phi 线段树
Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds ...
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- hdu 5828 Rikka with Sequence 线段树
Rikka with Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5828 Description As we know, Rik ...
- HDU 6089 Rikka with Terrorist (线段树)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6089 题解 这波强行维护搞得我很懵逼... 扫描线,只考虑每个点能走到左上方(不包括正上方,但包括正左 ...
- Rikka with Mista 线段树求交点个数
由于上下线段是不可能有交点的 可以先看左右线段树,按照y递增的顺序,对点进行排序. 升序构造,那么对于从某一点往下的射线,对于L,R进行区间覆盖,线段交点个数就是单点的被覆盖的次数. 降序构造,那么对 ...
- HDU5828 Rikka with Sequence 线段树
分析:这个题和bc round 73应该是差不多的题,当时是zimpha巨出的,那个是取phi,这个是开根 吐槽:赛场上写的时候直接维护数值相同的区间,然后1A,结果赛后糖教一组数据给hack了,仰慕 ...
- HDU 5828 Rikka with Sequence(线段树区间加开根求和)
Problem DescriptionAs we know, Rikka is poor at math. Yuta is worrying about this situation, so he g ...
- 牛客多校第十场 A Rikka with Lowbit 线段树
链接:https://www.nowcoder.com/acm/contest/148/A来源:牛客网 题目描述 Today, Rikka is going to learn how to use B ...
随机推荐
- C++:成员运算符重载函数和友元运算符重载函数的比较
5.2.4 成员运算符重载函数和友元运算符重载函数的比较 (1)对双目运算符而言,成员运算符重载函数参数表中含有一个参数,而友元运算符重载函数参数表中有两个参数:对于单目运算符而言,成员运算符重载函数 ...
- Android如何获取开机启动项列表
static final String BOOT_START_PERMISSION = "android.permission.RECEIVE_BOOT_COMPLETED"; p ...
- Django admin site(三)InlineModelAdmin
InlineModelAdmin class InlineModelAdminclass TabularInlineclass StackedInline 举例,有两个Model: from djan ...
- 写出完美论文的十个技巧10 Tips for Writing the Perfect Paper
10 Tips for Writing the Perfect Paper Like a gourmet meal or an old master painting, the perfect col ...
- asp.net Twilio
Imports System.Net Imports System.Text Imports Twilio Public Class clsTwilioSMS Public Shared Functi ...
- OSI七层协议
- Collection_Other
package com.bjsxt.others.que; import java.util.ArrayDeque; import java.util.Queue; /** * 使用队列模拟银行存款业 ...
- MyEclipse 常用设置
1.指定本机java环境 Windows-->preferences-->java-->Insetallel JREs 右侧 单击ADD-->standard VM--> ...
- Python之格式化输出讲解
1.格式化输出整数python print也支持参数格式化,与C言的printf似, strHello = "the length of (%s) is %d" %(Hello W ...
- Python3 学习第三弹:异常情况如何处理?
python 的处理错误的方式: 1> 断言 assert condition 相当于 if not condition: crash program 断言设置的目的就是因为与其让程序晚点崩溃, ...