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 这道题目和前面做的题目略有不同.以前的题目区间更新的时候都是统一更新的,也就是更新相同的值.但是这里不一样,这里更新的每 ...
随机推荐
- Git安装配置(完整版)
首先安装Windows客户端的git和TortoiseGit. 安装这两个软件还是蛮重要的,很多选项不能乱选. 为了写个完整的博客,我是装了又卸,卸了又装. 1.安装git 下载:https://gi ...
- Java 强引用 软引用 弱引用 虚引用详解
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt393 众所周知,java中是JVM负责内存的分配和回收,这是它的优点(使用方 ...
- 如何将ASP.NET-WebApi发布到IIS6.0上(转)
关于"如何将ASP.NET-WebApi发布到IIS6.0上"的这方面的学习,一开始项目组长让我们接触的时候,我的心情是这样的 哇呜.jpg 当时真的是一脸懵逼啊,对于刚接触asp ...
- Project 9:两种简单数列排序
1.冒泡法排序 /* 冒泡排序法的核心思想就是依次把最大的数换到最后面. 若有n个数 就需要通过n-1次循环来排序. 具体做法就是从第一个数开始 两个数比较大小大的换到后面,这样最大的就在最后了. 然 ...
- my new day in CNblog
感谢大家 今天正式在博客园平台开启我的第三个技术面博客 之前一直坚持在csdn平台撰文(http://blog.csdn.net/github_38885296)欢迎参观:) 因为觉得博客园知名度虽不 ...
- 字符编码笔记:ASCII,Unicode和UTF-8(转)
字符编码笔记:ASCII,Unicode和UTF-8 作者: 阮一峰 日期: 2007年10月28日 今天中午,我突然想搞清楚Unicode和UTF-8之间的关系,于是就开始在网上查资料. 结果,这个 ...
- 九度OJ 1016 火星A+B AC版
#include <iostream> #include <string.h> #include <sstream> #include <math.h> ...
- 团队作业4---第一次项目冲刺(ALpha)版本 第六天
一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 a.完成所有基础功能 b.正在进行测试调试 四.困难与问题 1.测试前没有理清业务逻辑,导致前期测试深度不够: 2.在验证过去 ...
- 201521123045 《Java程序设计》第6周学习总结
Java 第六周总结 1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结.注1:关键词与内容不求多,但概念之间的 ...
- Linux命令行学习
"mkdir + 文件夹名字" 创建文件夹 "pwd" 显示当前工作目录的绝对路径. "touch" 创建空文件. "cat /p ...