Yuanfang is puzzled with the question below: 
There are n integers, a 1, a 2, …, a n. The initial values of them are 0. There are four kinds of operations. 
Operation 1: Add c to each number between a x and a y inclusive. In other words, do transformation a k<---a k+c, k = x,x+1,…,y. 
Operation 2: Multiply c to each number between a x and a y inclusive. In other words, do transformation a k<---a k×c, k = x,x+1,…,y. 
Operation 3: Change the numbers between a x and a y to c, inclusive. In other words, do transformation a k<---c, k = x,x+1,…,y. 
Operation 4: Get the sum of p power among the numbers between a x and a y inclusive. In other words, get the result of a x p+a x+1 p+…+a y p
Yuanfang has no idea of how to do it. So he wants to ask you to help him. 

InputThere are no more than 10 test cases. 
For each case, the first line contains two numbers n and m, meaning that there are n integers and m operations. 1 <= n, m <= 100,000. 
Each the following m lines contains an operation. Operation 1 to 3 is in this format: "1 x y c" or "2 x y c" or "3 x y c". Operation 4 is in this format: "4 x y p". (1 <= x <= y <= n, 1 <= c <= 10,000, 1 <= p <= 3) 
The input ends with 0 0. 
OutputFor each operation 4, output a single integer in one line representing the result. The answer may be quite large. You just need to calculate the remainder of the answer when divided by 10007.Sample Input

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 题意:就是三种操作,一种加上一个数,一种乘上一个数,一种改为一个数,然后就是求最终一段区间每个数的几次方,相加。
题解:就是有一个基础值,然后就是存储其三次方,二次方,一次方的值,这样便于最后的输出,这个是十分十分复杂的。
如果在赛场上需要保持十分良好的心态才可以AC,三次方,二次方,一次方的更新,不是特别难,但是需要十分细心,以及
良好的耐心。
 #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#define lson(x) x*2
#define rson(x) x*2+1
using namespace std;
const int MAXN=;
const int mod=;
typedef long long LL;
int n,m,x,y,z,num;
struct hh{
int l,r,mid,add,mul,zhi[];
}tree[MAXN<<];
void push_up(int p)
{
for (int i=;i<;i++)
tree[p].zhi[i]=(tree[lson(p)].zhi[i]+tree[rson(p)].zhi[i])%mod;
}
void finish_work(int p,int mul,int add)
{
int len=tree[p].r-tree[p].l+;
tree[p].zhi[]=tree[p].zhi[]*mul%mod;
tree[p].zhi[]=tree[p].zhi[]*mul%mod*mul%mod;
tree[p].zhi[]=tree[p].zhi[]*mul%mod*mul%mod*mul%mod; tree[p].mul=tree[p].mul*mul%mod;
tree[p].add=(tree[p].add*mul%mod+add)%mod; tree[p].zhi[]=(tree[p].zhi[]+*add%mod*add%mod*tree[p].zhi[]%mod)%mod;
tree[p].zhi[]=(tree[p].zhi[]+*add%mod*tree[p].zhi[]%mod)%mod;
tree[p].zhi[]=(tree[p].zhi[]+len*add%mod*add%mod*add%mod)%mod;
tree[p].zhi[]=(tree[p].zhi[]+*add%mod*tree[p].zhi[]%mod)%mod;
tree[p].zhi[]=(tree[p].zhi[]+len*add%mod*add%mod)%mod;
tree[p].zhi[]=(tree[p].zhi[]+len*add%mod)%mod;
}
void push_down(int p)
{
if (tree[p].l==tree[p].r) return;
finish_work(lson(p),tree[p].mul,tree[p].add);
finish_work(rson(p),tree[p].mul,tree[p].add);
tree[p].mul=,tree[p].add=;
}
void build(int l,int r,int p)
{
tree[p].l=l,tree[p].r=r,tree[p].mid=(l+r)>>,tree[p].mul=;
tree[p].add=tree[p].zhi[]=tree[p].zhi[]=tree[p].zhi[]=;
if (l==r) return;
build(l,tree[p].mid,lson(p));
build(tree[p].mid+,r,rson(p));
}
void change(int l,int r,int p,int mul,int add)
{
//cout<<l<<" "<<r<<" "<<p<<endl;
if (l<=tree[p].l&&r>=tree[p].r) finish_work(p,mul,add);
else {
push_down(p);
if (r<=tree[p].mid) change(l,r,lson(p),mul,add);
else if (l>tree[p].mid) change(l,r,rson(p),mul,add);
else{
change(l,tree[p].mid,lson(p),mul,add);
change(tree[p].mid+,r,rson(p),mul,add);
}
push_up(p);
}
}
int query(int l,int r,int p,int num)
{
//cout<<l<<" "<<r<<" "<<p<<endl;
if (l<=tree[p].l&&r>=tree[p].r) return tree[p].zhi[num-];
push_down(p);
if (r<=tree[p].mid) return query(l,r,lson(p),num);
else if (l>tree[p].mid) return query(l,r,rson(p),num);
else return (query(l,tree[p].mid,lson(p),num)+query(tree[p].mid+,r,rson(p),num))%mod;
}
int main()
{
while (scanf("%d%d",&n,&m)&&(n+m))
{
build(,n,);
for (int i=;i<=m;i++)
{
scanf("%d%d%d%d",&num,&x,&y,&z);
if (num==) change(x,y,,,z);
else if (num==) change(x,y,,z,);
else if (num==) change(x,y,,,z);
else printf("%d\n",query(x,y,,z)%mod);
}
}
}
												

hdu4578 线段树 三次方,二次方,一次方的值的更多相关文章

  1. hdu 1754 I Hate It (线段树功能:单点更新和区间最值)

    版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...

  2. HDU4578 线段树(区间更新 + 多种操作)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4578  , 线段树的区间更新 + 多种操作,好题. 虽然是比较裸的线段树,但是比较麻烦,并且有很多细节 ...

  3. HDU4578 线段树(区间更新 + 多种操作)和平方,立方

    参考:https://www.cnblogs.com/H-Vking/p/4297973.html 题意: 虽然是比较裸的线段树,但是比较麻烦,并且有很多细节需要考虑,对着别人的ac代码debug了一 ...

  4. 算法模板——线段树6(二维线段树:区域加法+区域求和)(求助phile)

    实现功能——对于一个N×M的方格,1:输入一个区域,将此区域全部值作加法:2:输入一个区域,求此区域全部值的和 其实和一维线段树同理,只是不知道为什么速度比想象的慢那么多,求解释...@acphile ...

  5. 【可持久化线段树】POJ2104 查询区间第k小值

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 61284   Accepted: 21504 Ca ...

  6. hdu4578(线段树)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 题意:n个数,初始值为0,4种操作: 1.将某个区间所有值加上另一个值: 2.将区间所有值都乘上 ...

  7. hdu4578线段树区间更新

    /* 只有在区间中的数字不相同时才pushdown:往子区间传递数字再到子区间更新,同时该区间的flag置0 更新完左右子区间后进行pushup,如果左右子区间数字相同,那么把子区间合并,子区间数字置 ...

  8. HDU I Hate It(线段树单节点更新,求区间最值)

    http://acm.hdu.edu.cn/showproblem.php?pid=1754 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分 ...

  9. HDOJ-4027(线段树+区间更新(每个节点更新的值不同))

    Can You answer these queries? HDOJ-4027 这道题目和前面做的题目略有不同.以前的题目区间更新的时候都是统一更新的,也就是更新相同的值.但是这里不一样,这里更新的每 ...

随机推荐

  1. Entity Framework Core 2.0 中使用LIKE 操作符

    Entity Framework Core 2.0 中使用LIKE 操作符 不定时更新翻译系列,此系列更新毫无时间规律,文笔菜翻译菜求各位看官老爷们轻喷,如觉得我翻译有问题请挪步原博客地址 本博文翻译 ...

  2. NAT集群部署solo之session server

    author:JevonWei 版权声明:原创作品 使用Nginx做代理服务器,部署solo,使用session server做会话黏滞 拓扑图 环境 tomcatA 172.16.253.108 t ...

  3. 安装JDK详细步骤,以及环境变量配置

    1.JDK 1)下载:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 点击同意, ...

  4. main方法快速编辑日历

    public static void main(String[] args) { Scanner input=new Scanner (System.in); System.out.println(& ...

  5. 201521123099 《Java程序设计》第2周学习总结

    1. 本周学习总结 1.Java对我来说难度还是很大.需要花更多时间去学习. 2. 书面作业 1.使用Eclipse关联jdk源代码,并查看String对象的源代码(截图)?分析String使用什么来 ...

  6. 201521123039 《java程序设计》第十周学习总结

    1. 本周学习总结 2. 书面作业 本次PTA作业题集异常.多线程 finally 题目4-2 1.1 截图你的提交结果(出现学号) 1.2 4-2中finally中捕获异常需要注意什么? 总结:需要 ...

  7. Signal ()函数详细介绍 Linux函数(转)

    Signal ()函数详细介绍 Linux函数 收藏人:紫火神兵     2012-09-27 | 阅:5659  转:22    |   来源   |  分享               signa ...

  8. JDBC第一篇--【介绍JDBC、使用JDBC连接数据库、简单的工具类】

    1.什么是JDBC JDBC全称为:Java Data Base Connectivity,它是可以执行SQL语句的Java API 2.为什么我们要用JDBC 市面上有非常多的数据库,本来我们是需要 ...

  9. spring 注解方式配置Bean

    Spring能够从classpath下自动扫描,侦测和实例化具有特定注解的组件特定组件包括: @Component:基本注解,标示了一个受Spring管理的Bean组件 @Respository:标识 ...

  10. JSR303的数据校验-Hibernate Validator方式实现

    1.什么是JSR303? JSR303是java为bean数据合法性校验所提供的一个标准规范,叫做Bean Validation. Bean Validation是一个运行时的数据校验框架,在验证之后 ...