当前位置:网站首页>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
边栏推荐
- Dotconnect for DB2 Data Provider
- oracle连接池长时间不使用连接失效问题
- Oracle connection pool is not used for a long time, and the connection fails
- unrecognized selector sent to instance 0x10b34e810
- IDEA重启后无法创建Servlet文件的解决方案
- 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
- Oauth2协议中如何对accessToken进行校验
- Data analysis from the perspective of control theory
- Lavel PHP artisan automatically generates a complete set of model+migrate+controller commands
- uniapp的表单验证
猜你喜欢
左程云 递归+动态规划
Unity uses maskablegraphic to draw a line with an arrow
巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...
How to verify accesstoken in oauth2 protocol
Error: could not find a version that satisfies the requirement xxxxx (from versions: none) solutions
How to analyze fans' interests?
Development of wireless communication technology, cv5200 long-distance WiFi module, UAV WiFi image transmission application
tensorboard的使用
“零售为王”下的家电产业:什么是行业共识?
Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application
随机推荐
cocos3——8.实现初学者指南
惯导标定国内外研究现状小结(删减版)
Left value, right value
Redis入门完整教程:AOF持久化
[cpk-ra6m4 development board environment construction based on RT thread studio]
How to design interface test cases? Teach you a few tips to draft easily
Error: could not find a version that satisfies the requirement xxxxx (from versions: none) solutions
2022 information security engineer examination outline
Babbitt | metauniverse daily must read: is IP authorization the way to break the circle of NFT? What are the difficulties? How should holder choose the cooperation platform
How-PIL-to-Tensor
C language exercises_ one
Redis入门完整教程:复制原理
How does C language (string) delete a specified character in a string?
Simple bubble sort
Hazel engine learning (V)
Summary of research status of inertial navigation calibration at home and abroad (abridged version)
Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
Static proxy of proxy mode
Lost in the lock world of MySQL
知识图谱构建全流程