Transformation
hdu4578:http://acm.hdu.edu.cn/showproblem.php?pid=4578
题意:
给一个序列 {an},有 4 种操作。
1、将一段区间的数全部加 c。
2、将一段区间的数全部乘 c。
3、将一段区间的数全部等于 c。
4、询问一段区间的和(和、平方和、立方和)。
解题思路:
这道题自己完全不会打,虽然知道思路。所以借鉴了大神的代码。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 1e5 + ;
const int mod = ;
#define lson u<<1
#define rson u<<1|1 inline int sqr2(int x){
return x * x % mod;
} inline int sqr3(int x){
return sqr2(x) * x % mod;
} struct SegTree{
int l,r;
int sum[];
int mul,add;
inline int mid(){
return (l+r)>> ;
}
inline int len(){
return r-l+;
}
void flag_init(){
add = , mul = ;
}
void to_mul(int m){
(sum[] *= m) %= mod;
(sum[] *= sqr2(m)) %= mod;
(sum[] *= sqr3(m)) %= mod; (mul *= m) %= mod;
(add *= m) %= mod;
}
void to_add(int a){
(sum[] += sqr3(a) * len()) %= mod;
(sum[] += * a * sum[]) %= mod;
(sum[] += * sqr2(a) * sum[]) %= mod; (sum[] += sqr2(a) * len()) %= mod;
(sum[] += * a * sum[]) %= mod; (sum[] += a * len()) %= mod; (add += a) %= mod;
}
}T[N<<];
void build(int u,int l,int r){
T[u].l = l , T[u].r = r;
memset(T[u].sum,,sizeof(T[u].sum));
T[u].flag_init();
if(l==r)
return ;
int m = T[u].mid();
build(lson,l,m);
build(rson,m+,r);
}
int op;
void push_down(int u){
T[lson].to_mul(T[u].mul);
T[rson].to_mul(T[u].mul);
T[lson].to_add(T[u].add);
T[rson].to_add(T[u].add);
T[u].flag_init();
}
void push_up(int u){
for(int i=;i<=;i++)
T[u].sum[i] = (T[lson].sum[i] + T[rson].sum[i]) % mod;
} void updata(int u,int l,int r,int mul,int add){
if(T[u].l == l && T[u].r == r){
T[u].to_mul(mul);
T[u].to_add(add);
return ;
}
push_down(u);
int m = T[u].mid();
if(r <= m)
updata(lson,l,r,mul,add);
else if(l >m)
updata(rson,l,r,mul,add);
else
updata(lson,l,m,mul,add), updata(rson,m+,r,mul,add);
push_up(u);
}
int query(int u,int l,int r){
if(T[u].l == l && T[u].r == r)
return T[u].sum[op];
push_down(u);
int m = T[u].mid();
if(r <= m)
return query(lson,l,r);
else if(l >m)
return query(rson,l,r);
else
return (query(lson,l,m)+query(rson,m+,r)) % mod;
} int main(){
int n,m,a,b,c;
while(scanf("%d%d",&n,&m),n||m){
build(,,n+);
while(m--){
scanf("%d",&op);
if(op == ){
scanf("%d%d%d",&a,&b,&op);
printf("%d\n",query(,a,b));
}
else{
scanf("%d%d%d",&a,&b,&c);
if(op == )
updata(,a,b,,c);
else if(op == )
updata(,a,b,c,);
else
updata(,a,b,,c);
}
}
}
return ;
}
Transformation的更多相关文章
- (七)Transformation和action详解-Java&Python版Spark
Transformation和action详解 视频教程: 1.优酷 2.YouTube 什么是算子 算子是RDD中定义的函数,可以对RDD中的数据进行转换和操作. 算子分类: 具体: 1.Value ...
- 线性分式变换(linear fractional transformation)
线性分式变换(linear fractional transformation)的名称来源于其定义的形式:(ax+b)/(cx+d),其中分子分母是线性的,然后最外层是一个分式形式,所以叫做这个名字, ...
- OLE DB Command transformation 用法
OLE DB Command transformation component 能够引用参数,逐行调用sqlcommand,This transformation is typically used ...
- OpenCASCADE General Transformation
OpenCASCADE General Transformation eryar@163.com Abstract. OpenCASCADE provides a general transforma ...
- Informatica Lookup Transformation组件的Connect 与Unconnected类型用法
Informatica Lookup Transformation组件的Connect 与Unconnected类型用法及区别:下面是通一个Lookup在不同Mapping中的使用: 1. Conne ...
- Data Transformation / Learning with Counts
机器学习中离散特征的处理方法 Updated: August 25, 2016 Learning with counts is an efficient way to create a compact ...
- VS非web项目使用Transformation配置文件
Web项目中的Transformation使用起来非常方便,特别是本地与服务器情况不一致时调试下以及webdeploy的配合使用. 步骤: 1. 在项目中新建App.Debug.Config及App. ...
- SAP SLT (Landscape Transformation) 企业定制培训
No. Item Remark 1 SAP SLT概述 SAP Landscape Transformation Overview 2 SAP SLT 安装与配置<1> for abap ...
- Scalaz(55)- scalaz-stream: fs2-基础介绍,fs2 stream transformation
fs2是scalaz-stream的最新版本,沿用了scalaz-stream被动式(pull model)数据流原理但采用了全新的实现方法.fs2比较scalaz-stream而言具备了:更精简的基 ...
- 使用Web.Config Transformation配置灵活的配置文件
发布Asp.net程序的时候,开发环境和发布环境的Web.Config往往不同,比如connectionstring等.如果常常有发布的需求,就需要常常修改web.config文件,这往往是一件非常麻 ...
随机推荐
- 有关Transaction not successfully started问题解决的方法
我的项目配置:struts2+hibernate3.3+spring3.2.5 主要问题:在进行更新和提交操作时出现下面异常 org.springframework.transaction.Trans ...
- SSL 错误
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? at com.sun.net.ssl.in ...
- empty函数PHP
empty译为: adj.空的,空虚的,空洞的;空闲的,无效的,徒劳的;无聊的,愚蠢的;言语或行动空洞的 vt.(使)成为空的, 把…弄空;把…腾出来 vi.成为空的;流空 n.空车;空的东西 是PH ...
- 9.23 noip模拟试题
Problem 1 抓牛(catchcow.cpp/c/pas) [题目描述] 农夫约翰被通知,他的一只奶牛逃逸了!所以他决定,马上出发,尽快把那只奶牛抓回来. 他们都站在数轴上.约翰在N(O≤N ...
- HTML5小游戏源码收藏
html5魅族创意的贪食蛇游戏源码下载 html5网页版打砖块小游戏源码下载 html5 3D立体魔方小游戏源码下载 html5网页版飞机躲避游戏源码下载 html5三国人物连连看游戏源码下载 js ...
- TextView使用Spannable设置复合文本
http://blog.csdn.net/linghu_java/article/details/32053167 Spannable 对文字的编辑减少TextView的拼接并且达到改变一串字符中的部 ...
- recursive - simple screenshot but detail principle.
the code below demonstates the principle of the'recursive-call' that the programing beginner may be ...
- ashx页面 “检测到有潜在危险的 Request.Form 值”的解决方法(控制单个处理程序不检测html标签)
如题: 使用web.config的configuration/location节点. 在configuration节点内新建一个location节点,注意这个节点和system.webserver那些 ...
- 文字排版--删除线(text-decoration:line-through)
如果想在网页上设置删除线怎么办,这个样式在电商网站上常会见到: 上图中的原价上的删除线使用下面代码就可以实现: .oldPrice{text-decoration:line-through;}
- CSS布局模型思考
flow模型:默认布局模型,元素从左向右.从上到下依次排列,块状元素独占一行.Position属性对应值static. float模型:主要效果是让本来独占一行的块状元素变成内联-块状元素,并到一排显 ...