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. Oracle:解锁scott用户及设置密码

    关于Oracle 10g scott用户解锁的方法两则 解决方法一. 首先确认已经安装oracle 数据库和客户端 在客户端DOS下执行如下语句: 注意提示符号 c:\sqlplus /nolog s ...

  2. Spring MVC入门讲解

    一.Springmvc是什么? Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想, 将web层进行职责解耦,基 ...

  3. NHibernate教程(7)--并发控制

    本节内容 什么是并发控制? 悲观并发控制(Pessimistic Concurrency) 乐观并发控制(Optimistic Concurrency) NHibernate支持乐观并发控制 实例分析 ...

  4. 201521123019 《Java程序设计》第7周学习总结

    1. 本章学习总结 2. 书面作业 Q1.ArrayList代码分析 1.1解释ArrayList的contains源代码 源代码如下: public boolean contains(Object ...

  5. 201521123122 《java程序设计》 第四周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. 这个思维导图比较简单,详细内容点击此处 2. 书面作业 注释的应用 使用类的注释与方法的注释 ...

  6. 201521123063 《Java程序设计》第三周学习总结

    1.本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识组织起来.请使用纸笔或者下面的工具画出本周学习到的知识点.截图或者拍照上传. 2.书面作业 ...

  7. Android四大组件(详细总结)

    android四大组件分别为activity.service.content provider.broadcast receiver. 一.android四大组件详解 1.activity (1)一个 ...

  8. 201521123122 《java程序设计》第十周学习总结

    ## 201521123122 <java程序设计>第十周实验总结 ## 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. 2. 书面作业 本次P ...

  9. 201521123028 《Java程序设计》第12周学习总结

    1. 本周学习总结 流与文件 I/O流:Input/Output处理的简称,本质上就是一个数据序列.分为输入流Input Stream和输出流Output Stream. 最基本的可处理数据单位-by ...

  10. phpcms总结(转)

    转自:http://www.cnblogs.com/zuzwn/p/3649536.html文件目录结构 根目录 | – api 接口文件目录 | – caches 缓存文件目录 | – config ...