当前位置:网站首页>HDU ACM 4578 Transformation-> Segment tree - interval change
HDU ACM 4578 Transformation-> Segment tree - interval change
2022-07-07 03:11:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack
analysis : Complex business segment tree .
There is only one query operation , It's a requirement [l,r] Between the number of p Sum of thorium . Not all queries, all nodes , meeting TLE. The best part is the query part [a.b]. We are equal for all of these interval values , I can return to (b-a+1)*val Value . An interval in which all values in the interval are the same . For initial value setting and addition and multiplication operations . There are two situations :1、 When it is set to initial value . Just cover the interval directly . And assign the marked addition and multiplication operation as the initial value .2、 When it is an addition and multiplication operation . First, infer whether the current interval segment is the same value , If yes, add and multiply directly , Maintain the same value . Assumptions are different , See whether the interval has an addition and multiplication mark , Pass this addition and multiplication mark all the way down . Stop until you meet the same value of that interval . Finally, assign this addition and multiplication to the initial interval . Simply put , The override operation can be maintained directly , If it is not an override operation . Only one addition and multiplication operation can be reserved in the interval .
#include<iostream>
using namespace std;
#define lz t<<1,l,mid // Left interval
#define rz (t<<1)|1,mid+1,r // The right range
#define N 100005
#define MOD 10007
__int64 add[N<<2],mul[N<<2],chan[N<<2],sum[N<<2];
void Build(int t,int l,int r) // Create a line tree
{
int mid;
mul[t]=1;
add[t]=sum[t]=0;
chan[t]=0;
if(l==r)
{
chan[t]=1; // Set leaf node to 1. Convenient inquiry
return ;
}
mid=(l+r)>>1;
Build(lz);
Build(rz);
}
void PushDown(int t,int l,int r) // Mark down
{
int mid;
if(l==r) return ;
mid=(l+r)>>1;
if(chan[t]) //set Mark down
{
add[t<<1]=0,mul[t<<1]=1;
add[(t<<1)|1]=0,mul[(t<<1)|1]=1;
chan[t<<1]=chan[(t<<1)|1]=1;
sum[t<<1]=sum[(t<<1)|1]=sum[t];
chan[t]=0;
}
else
{
if(add[t]) // Mark and download
{
if(chan[t<<1]) sum[t<<1]=(sum[t<<1]+add[t])%MOD; // Zuo Zi Shu you set Mark
else
{
PushDown(lz); // Next
add[t<<1]=(add[t<<1]+add[t])%MOD;
}
if(chan[(t<<1)|1]) sum[(t<<1)|1]=(sum[(t<<1)|1]+add[t])%MOD; // Zuo Zi Shu you set Mark
else
{
PushDown(rz); // Next
add[(t<<1)|1]=(add[(t<<1)|1]+add[t])%MOD;
}
add[t]=0;
}
if(mul[t]>1) // Multiply the mark and pass it down
{
if(chan[t<<1]) sum[t<<1]=(sum[t<<1]*mul[t])%MOD; // Zuo Zi Shu you set Mark
else
{
PushDown(lz); // Next
mul[t<<1]=(mul[t<<1]*mul[t])%MOD;
}
if(chan[(t<<1)|1]) sum[(t<<1)|1]=(sum[(t<<1)|1]*mul[t])%MOD; // Zuo Zi Shu you set Mark
else
{
PushDown(rz); // Next
mul[(t<<1)|1]=(mul[(t<<1)|1]*mul[t])%MOD;
}
mul[t]=1;
}
}
}
void Update(int t,int l,int r,int ul,int ur,int c,int op)
{
int mid;
if(l>=ul && ur>=r) // The border
{
if(op==3)
chan[t]=1,mul[t]=1,add[t]=0,sum[t]=c;
else if(chan[t])
{
if(op==1) sum[t]=(sum[t]+c)%MOD;
else sum[t]=(sum[t]*c)%MOD;
}
else
{
PushDown(t,l,r); // Next
if(op==1) add[t]=(add[t]+c)%MOD;
else mul[t]=(mul[t]*c)%MOD;
}
return ;
}
PushDown(t,l,r);
mid=(l+r)>>1;
if(ur<=mid) Update(lz,ul,ur,c,op);
else if(ul>mid) Update(rz,ul,ur,c,op);
else
{
Update(lz,ul,mid,c,op);
Update(rz,mid+1,ur,c,op);
}
}
__int64 Query(int t,int l,int r,int ul,int ur,int p)
{
int mid,i;
__int64 ans,tp,t1,t2;
if(ul<=l && r<=ur)
if(chan[t])
{
ans=1;
tp=sum[t];
for(i=1;i<=p;i++) ans=(ans*tp)%MOD;
return (r-l+1)*ans%MOD; // Because every part of the interval is the same
}
PushDown(t,l,r); // Mark down
mid=(l+r)>>1;
if(ur<=mid) return Query(lz,ul,ur,p);
else if(ul>mid) return Query(rz,ul,ur,p);
else
{
t1=Query(lz,ul,mid,p);
t2=Query(rz,mid+1,ur,p);
return (t1+t2)%MOD;
}
}
int main()
{
int n,m,i,l,r,c,op;
while(scanf("%d%d",&n,&m)==2 && n+m)
{
Build(1,1,n); //1 Root node
for(i=1;i<=m;i++)
{
scanf("%d%d%d%d",&op,&l,&r,&c);
if(op<=3) Update(1,1,n,l,r,c,op);
else
printf("%I64d\n",Query(1,1,n,l,r,c)%MOD);
}
}
return 0;
}Copyright notice : This article is the original article of the blogger . Blog , Do not reprint without permission .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116783.html Link to the original text :https://javaforall.cn
边栏推荐
- MOS transistor realizes the automatic switching circuit of main and auxiliary power supply, with "zero" voltage drop and static current of 20ua
- tensorboard的使用
- A complete tutorial for getting started with redis: problem location and optimization
- leetcode-02(链表题)
- Static proxy of proxy mode
- Redis入门完整教程:客户端常见异常
- Make (convert) ICO Icon
- 杰理之发射端在接收端关机之后假死机【篇】
- A complete tutorial for getting started with redis: RDB persistence
- Cocos2d-x box2d physical engine compilation settings
猜你喜欢

Es6中Promise的使用

知识图谱构建全流程
![[socket] ① overview of socket technology](/img/91/dccbf27a17418ea632c343551bccc0.png)
[socket] ① overview of socket technology

IDEA重启后无法创建Servlet文件的解决方案

input_delay

Le tube MOS réalise le circuit de commutation automatique de l'alimentation principale et de l'alimentation auxiliaire, et la chute de tension "zéro", courant statique 20ua

【2022国赛模拟】多边形——计算几何、二分答案、倍增
![[cpk-ra6m4 development board environment construction based on RT thread studio]](/img/08/9a847c73d6da6fc74d84af56897752.png)
[cpk-ra6m4 development board environment construction based on RT thread studio]

Left path cloud recursion + dynamic planning

首届“量子计算+金融科技应用”研讨会在京成功举办
随机推荐
腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》
2022年信息安全工程师考试大纲
Redis getting started complete tutorial: replication configuration
C language string sorting
CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计
尚硅谷JVM-第一章 类加载子系统
Laravel php artisan 自动生成Model+Migrate+Controller 命令大全
How-PIL-to-Tensor
硬件之OC、OD、推挽解释
Es6中Promise的使用
Es6中Promise的使用
cocos3——8. Implementation Guide for beginners
Shell 编程基础
oracle连接池长时间不使用连接失效问题
Redis introduction complete tutorial: replication principle
Cocos2d-x box2d physical engine compilation settings
Install redis from zero
Qt蓝牙:QBluetoothDeviceInfo
Appx代码签名指南
C language exercises_ one