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文件,这往往是一件非常麻 ...
随机推荐
- C# 自动登录网页,浏览页面【转载】
需求:客户的数据同时存在在另外一个不可控的系统中,需要和当前系统同步. 思路:自动登录另外一个系统,然后抓取数据,同步到本系统中. 技术点:模拟用户登录:保存登录状态:抓取数据 /// <sum ...
- 另5个你不知道的HTML5接口API
原文地址: 5 More HTML5 APIs You Didn’t Know Existed 演示地址: 全屏API Demo 原文日期: 2012年11月08日 翻译日期: 2013年08月13日 ...
- xml写代码
#include <QDomDocument> #include <QtGui> int main(int argc, char *argv[]) { QApplication ...
- iOS-UITouch,UIEvent使用介绍
UITouch 当用户用一根手指触摸屏幕时,会创建一个与手指相关联的UITouch对象 一根手指对应一个UITouch对象 UITouch的作用 保存着跟手指相关的信息,比如触摸的位置.时间.阶段 当 ...
- 《Android群英传》读书笔记 (5) 第十一章 搭建云端服务器 + 第十二章 Android 5.X新特性详解 + 第十三章 Android实例提高
第十一章 搭建云端服务器 该章主要介绍了移动后端服务的概念以及Bmob的使用,比较简单,所以略过不总结. 第十三章 Android实例提高 该章主要介绍了拼图游戏和2048的小项目实例,主要是代码,所 ...
- Java web 文件下载
/** * 下载文件 * @param msg */ public boolean printOutFile(String fileFullName,String fileName) { if (fi ...
- ubuntu环境配置之vi 配置【转载】
ubuntu环境配置之vi 配置 [日期:2014-02-10] 来源:Linux社区 作者:zhonghe1114 [字体:大 中 小] Android的源码开发,几乎离不开Linux,Lin ...
- 我的博客css得到别人的认可
你好 在吗?? 本消息来自QQ临时会话,如果您收到骚扰信息,可点击以下网址中的"停用服务"关闭临时会话: http://shang.qq.com/widget/set.php 20 ...
- NgNice项目案例
技术构架: 服务端技术:NodeJS + Express4.x + Mongodb + Mongoose 前端技术: AngularJS1.2.x + Bootstrap3.x 源码:https:// ...
- javascript DOM小结
一:定义 dom:文档对象模型. dom是针对HTML和XML文档的一个API.dom描绘了一个层次化的节点树,允许开发人员添加.移除.修改页面的某一部分. 1:childNodes(返回当前节点的子 ...