hdu4578 线段树 三次方,二次方,一次方的值
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 线段树 三次方,二次方,一次方的值的更多相关文章
- hdu 1754 I Hate It (线段树功能:单点更新和区间最值)
版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...
- HDU4578 线段树(区间更新 + 多种操作)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 , 线段树的区间更新 + 多种操作,好题. 虽然是比较裸的线段树,但是比较麻烦,并且有很多细节 ...
- HDU4578 线段树(区间更新 + 多种操作)和平方,立方
参考:https://www.cnblogs.com/H-Vking/p/4297973.html 题意: 虽然是比较裸的线段树,但是比较麻烦,并且有很多细节需要考虑,对着别人的ac代码debug了一 ...
- 算法模板——线段树6(二维线段树:区域加法+区域求和)(求助phile)
实现功能——对于一个N×M的方格,1:输入一个区域,将此区域全部值作加法:2:输入一个区域,求此区域全部值的和 其实和一维线段树同理,只是不知道为什么速度比想象的慢那么多,求解释...@acphile ...
- 【可持久化线段树】POJ2104 查询区间第k小值
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 61284 Accepted: 21504 Ca ...
- hdu4578(线段树)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 题意:n个数,初始值为0,4种操作: 1.将某个区间所有值加上另一个值: 2.将区间所有值都乘上 ...
- hdu4578线段树区间更新
/* 只有在区间中的数字不相同时才pushdown:往子区间传递数字再到子区间更新,同时该区间的flag置0 更新完左右子区间后进行pushup,如果左右子区间数字相同,那么把子区间合并,子区间数字置 ...
- HDU I Hate It(线段树单节点更新,求区间最值)
http://acm.hdu.edu.cn/showproblem.php?pid=1754 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分 ...
- HDOJ-4027(线段树+区间更新(每个节点更新的值不同))
Can You answer these queries? HDOJ-4027 这道题目和前面做的题目略有不同.以前的题目区间更新的时候都是统一更新的,也就是更新相同的值.但是这里不一样,这里更新的每 ...
随机推荐
- SVN 通过IIS设置反向代理访问
原因 一个字,穷,没办法,只有一台机器 要当测试服务器还要做源码管理. 解决办法 通过IIS配置反向代理访问SVN,给SVN访问的HTTPS绑定上域名,就可以正常访问了. 1.修改SVN配置 把SVN ...
- Spring mvc 转发、重定向
spring控制器最后返回一个ModelAndView(urlName),其中urNamel可以是一个视图名称,由视图解析器负责解析后将响应流写回客户端;也可以通过redirect/forward:u ...
- setTimeout,setInterval你不知道的…
javascript线程解释(setTimeout,setInterval你不知道的事) 标签: javascript引擎任务浏览器functionxmlhttprequest 2011-11-21 ...
- 使用BootStrap框架设置全局CSS样式
一.排版 标题 HTML 中的所有标题标签,<h1> 到 <h6> 均可使用.另外,还提供了 .h1 到 .h6 类,为的是给内联(inline)属性的文本赋予标题的样式. & ...
- 【集美大学1411_助教博客】团队作业2——需求分析&原型设计 成绩
首先要向各位同学道歉,最近助教的工作较多,并且伴随着频繁的出差,评论博客和评分都不及时,以致于同学们都没有得到反馈,在此我要表示歉意.其次,对于第二次团队作业,有两个团队没有提交到班级博客中但按时完成 ...
- 【Alpha】第四次Daily Scrum Meeting
GIT 一.今日站立式会议照片 二.会议内容 1.采取老师提出的建议,考虑对送礼对象进行一个分类,这个在服务功能模块中完善. 2.回顾之前几次会议的内容,做一个小的总结,各抒己见,对每个人哪方面做得比 ...
- 201521123088《JAVA程序设计》第8周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 2. 书面作业 本次作业题集集合 1.List中指定元素的删除(题目4 ...
- 201521123102 《Java程序设计》第4周学习总结
1. 本周学习总结 2. 书面作业 Q1.注释的应用 使用类的注释与方法的注释为前面编写的类与方法进行注释,并在Eclipse中查看.(截图) 类的注释: 方法的注释: Q2.面向对象设计(大作业1- ...
- 201521123113 《Java程序设计》第2周学习总结
1.本周学习总结 学习了各种java数据类型以及各种运算符的使用 string类之所以好用是因为这是人可以看得懂的类型,操作简便 Scanner扫描器与标准输出输入用法上的不同,Scanner较标准输 ...
- 第2周作业-Java基本语法与类库(20170227-20170304)
本周学习总结 (1)这周学习认识和熟悉了java的一些类型和变量: (2)学习了java的运算符基本使用方法: (3)了解了如何建立远程仓库和本地仓库,和如何让java代码在临时储存,本地仓库和远程仓 ...