HDU4578-Transformation-线段树的加、乘、变、次方操作
5 5
3 3 5 7
1 2 4 4
4 1 5 2
2 2 5 8
4 3 5 3
0 0
Sample Output
307
7489 题意:
给出n,m,表示该数有n个节点,m次操作。
接下来m次操作,op、x、y、z,
op=1时,将区间内每个元素+z
op=2时,将区间内每个元素*z
op=3时,将区间内每个元素都变成z
op=4时,求出区间内每个元素的p次方之和输出且对mod10007取余。 数组说明:
a[i]:该区间相等元素值
book[i]: 假设该节点下面的儿子节点全部相等则标记为0,否则为1
对于op=4时的次方操作:
if(L<=l&&r<=R&&book[i]==)
{
ll ans=;
for(int k=; k<p; k++)
ans=(ans*a[i])%mod;
ans=(ans*(r-l+))%mod;
return ans;
}
#include<stdio.h>
#include<map>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stack>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
const int mod=;
const int N=1e5+; int a[*N];
bool book[*N]; void pushdown(int i)
{
if(book[i<<]||book[i<<|])
book[i]=;
else if(a[i<<]!=a[i<<|])
book[i]=;
else
{
book[i]=;
a[i]=a[i<<]=a[i<<|];//因为a[i<<1]==a[i<<1|1]
}
}
//1 x y 1 n
void update(int i,int L,int R,int l,int r,int z,int op)
{
if(L<=l&&r<=R&&book[i]==)//1不相等 0相等
{
if(op==)
a[i]=(a[i]+z)%mod;
else if(op==)
a[i]=(a[i]*z)%mod;
else if(op==)
a[i]=z;
return;
}
if(book[i]==)
{
book[i<<]=book[i<<|]=;
a[i<<]=a[i<<|]=a[i];
book[i]=;
}
int mid=(l+r)>>;
if(L<=mid)
update(i<<,L,R,l,mid,z,op);
if(R>mid)
update(i<<|,L,R,mid+,r,z,op);
pushdown(i);//a[i]=a[i<<1]+a[i<<1|1];
} ll query(int i,int L,int R,int l,int r,int p)
{
if(L<=l&&r<=R&&book[i]==)
{
ll ans=;
for(int k=;k<p;k++)
ans=(ans*a[i])%mod;
ans=(ans*(r-l+))%mod;
return ans;
}
if(book[i]==)
{
book[i<<]=book[i<<|]=;
a[i<<]=a[i<<|]=a[i];
book[i]=;
}
int mid=(l+r)>>;
ll ans=;
if(L<=mid)
ans+=query(i<<,L,R,l,mid,p);
if(R>mid)
ans+=query(i<<|,L,R,mid+,r,p);
return ans%mod; } int main()
{
int n,m,op,L,R,z;
while(cin>>n>>m)
{
if(n==&&m==)
break;
memset(book,,sizeof(book));//假设全相等标记为0//book[1]表示该节点下面的元素不相等
memset(a,,sizeof(a));//该区间相等元素值
for(int i=; i<m; i++)
{
cin>>op>>L>>R>>z;
if(op!=) //1+,2*,3变为z,
update(,L,R,,n,z,op);
else //*z次方
{
ll ans=query(,L,R,,n,z)%mod;
printf("%lld\n",ans);
}
}
}
return ;
}
HDU4578-Transformation-线段树的加、乘、变、次方操作的更多相关文章
- HDU4578 Transformation 线段树
这个题让我重新学习了加 乘 在区间的操作 题解:http://blog.csdn.net/guognib/article/details/25324025?utm_source=tuicool& ...
- 【CF52C】Circular RMQ(线段树区间加减,区间最值)
给定一个循环数组a0, a1, a2, …, an-1,现在对他们有两个操作: Inc(le, ri, v):表示区间[le, ri]范围的数值增加v Rmq(le, ri):表示询问区间[le, r ...
- hdu 4578 Transformation 线段树多种操作裸题
自己写了一个带结构体的WA了7.8次 但是测了几组小数据都对..感觉问题应该出在模运算那里.写完这波题解去对拍一下. 以后线段树绝不写struct!一般的struct都带上l,r 但是一条线段的长度确 ...
- vijos 1659 河蟹王国 线段树区间加、区间查询最大值
河蟹王国 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 https://vijos.org/p/1659 Description 河蟹王国有一位河蟹国王,他 ...
- 30-Transformation(HDU4578)-区间线段树(复杂)
http://acm.hdu.edu.cn/showproblem.php?pid=4578 Transformation Time Limit: 15000/8000 MS (Java/Others ...
- poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和
A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?i ...
- poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和(模板)
A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?i ...
- Transformation 线段树好题 好题 (独立写出来对线段树不容易)
Transformation Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others)T ...
- 线段树 区间加 gcd 差分 小阳的贝壳
小阳的贝壳 如果线段树要维护区间gcd 这个很简单,但是如果有了区间加,维护gcd 就比较麻烦了. 这个首先可以证明的是 gcd(x,y,z)=gcd(x,y-x,z-y) 这个可以推到 n 个 ...
- HDU 4578 Transformation --线段树,好题
题意: 给一个序列,初始全为0,然后有4种操作: 1. 给区间[L,R]所有值+c 2.给区间[L,R]所有值乘c 3.设置区间[L,R]所有值为c 4.查询[L,R]的p次方和(1<=p< ...
随机推荐
- python with as 以上这段代码执行完毕后,就算在处理过程中出问题了,文件 f 总是会关闭。
with open("myfile.txt") as f: for line in f: print(line, end="") 以上这段代码执行完毕后,就算在 ...
- C#进阶系列——WebApi 路由机制剖析:你准备好了吗? 转载https://www.cnblogs.com/landeanfen/p/5501490.html
阅读目录 一.MVC和WebApi路由机制比较 1.MVC里面的路由 2.WebApi里面的路由 二.WebApi路由基础 1.默认路由 2.自定义路由 3.路由原理 三.WebApi路由过程 1.根 ...
- [python面试题] 什么是单例,单例有什么用,业务场景是什么
单例概念: 单例是一个特殊的类,这个类只能创建一次实例,例子如下: 1.a = Std(name='leo'), b = Std(name='jack'),两者的指向都是name=‘leo’的对象: ...
- Modify PDF operators.
1 Depart Process: 2 1. Grep xref and trailer binary position in file. 3 2. Dump xref table and trail ...
- LightOJ 1418 Trees on My Island (Pick定理)
题目链接:LightOJ 1418 Problem Description I have bought an island where I want to plant trees in rows an ...
- Mysql 2019-07-01
- Linux目录及说明
Linux目录及说明 [常见目录说明] 目录 /bin 存放二进制可执行文件(ls,cat,mkdir等),常用命令一般都在这里. /etc 存放系统管理和配置文件 /home 存放所有用户文件的根目 ...
- Spring学习笔记(14)——注解零配置
我们在以前学习 Spring 的时候,其所有的配置信息都写在 applicationContext.xml 里,大致示例如下: java代码: <beans> <bean n ...
- seaweedfs使用记录
搭建seaweedfs 在github上面clone,然后cd到docker目录使用docker-compose up -d就可以启动seaweedfs 启动以后通过xxx:9333可以看到效果 上传 ...
- string(81) "SQLSTATE[HY000]: General error: 1364 Field 'content' doesn't have a default value"
mysql版本是5.7.26,在插入数据时报错: string(81) "SQLSTATE[HY000]: General error: 1364 Field 'content' doesn ...