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. django框架简介

    -------------------MVC与MVT框架-------------------1.MVC MVC框架的核心思想是:解耦.降低各功能模块之间的耦合性,方便将来变化时,更容易重构代码,最大 ...

  2. HTML5新结构标签和移动端页面布局

    --------------------HTML5新结构标签--------------------1.h5新增的主要语义化标签如下: 1.header 页面头部.页眉 2.nav 页面导航 3.ar ...

  3. Apple公司开发者账号申请(2017包含邓白氏码申请)

    1.首先看需要那种账号 2.这个需要的是公司开发者账号,首先我们注册一个普通apple账号 打开网址 https://developer.apple.com 进入点击Account 进入登录页面,点击 ...

  4. 八大排序算法---基于python

    本文节选自:http://python.jobbole.com/82270/ 本文用Python实现了插入排序.希尔排序.冒泡排序.快速排序.直接选择排序.堆排序.归并排序.基数排序. 1.插入排序 ...

  5. chrome开发工具指南(十一)

    检查资源 使用 Application 面板的 Frames 窗格可以按框架组织资源. 您也可以在 Sources 面板中停用 Group by folder 选项,按框架查看资源. 要按网域和文件夹 ...

  6. 如何部署 Calico 网络?- 每天5分钟玩转 Docker 容器技术(67)

    Calico 是一个纯三层的虚拟网络方案,Calico 为每个容器分配一个 IP,每个 host 都是 router,把不同 host 的容器连接起来.与 VxLAN 不同的是,Calico 不对数据 ...

  7. html5中的video标签和audio标签

    不管是否承认,flash早已不像过往那样如日中天了.亚马逊全面放弃flash.苹果放弃flash.安卓也放弃了移动端的flash支持.事实上flash已经不太适合web开发了,因为HTML5中的vid ...

  8. 基于JZ2440开发板编写bootloader总结(一)

    凡走过必留下痕迹,学点什么都会有用的. 本系列博文总结了自己在学习嵌入式Linux编程过程中的收获,若有错误,恳请指正,谢谢! --参考教材韦东山系列教材 bootloader 是一个用于启动linu ...

  9. Beta版本测试报告以及Beta版本发布说明

    Beta版本测试报告 请根据团队项目中软件的需求文档.功能说明.系统设计和Beta阶段的计划安排,写出软件的测试过程和测试结果,并回答下述问题. 在测试过程中总共发现了多少bug?每个类别的bug分别 ...

  10. 团队作业8——第二次项目冲刺(Beta阶段)5.22

    1.当天站立式会议照片 会议内容: ①:检查总结上次任务完成情况 ②:安排本次任务的分工 ③:反思前三次自己的不足 ④:协商解决代码进度.成员投入时间等问题 2.每个人的工作 工作中遇到的困难: 代码 ...