Problem Description
Tired of playing computer games, alpc23 is planning to play a game on numbers. Because plus and subtraction is too easy for this gay, he wants to do some multiplication in a number sequence. After playing it a few times, he has found it is also too boring. So he plan to do a more challenge job: he wants to change several numbers in this sequence and also work out the multiplication of all the number in a subsequence of the whole sequence.
  To be a friend of this gay, you have been invented by him to play this interesting game with him. Of course, you need to work out the answers faster than him to get a free lunch, He he…

 
Input
The first line is the number of case T (T<=10).
  For each test case, the first line is the length of sequence n (n<=50000), the second line has n numbers, they are the initial n numbers of the sequence a1,a2, …,an, 
Then the third line is the number of operation q (q<=50000), from the fourth line to the q+3 line are the description of the q operations. They are the one of the two forms:
0 k1 k2; you need to work out the multiplication of the subsequence from k1 to k2, inclusive. (1<=k1<=k2<=n) 
1 k p; the kth number of the sequence has been change to p. (1<=k<=n)
You can assume that all the numbers before and after the replacement are no larger than 1 million.
 
Output
For each of the first operation, you need to output the answer of multiplication in each line, because the answer can be very large, so can only output the answer after mod 1000000007.
 
Sample Input
1
6
1 2 4 5 6 3
3
0 2 5
1 3 7
0 2 5
 
Sample Output
240
420

【题意】给出n个数,进行m次操作,0 x y就是求x到y区间的总乘积,1 x y就是把x的位置上的数改为y

【思路】线段树单点更新问题

#include<iostream>
#include<stdio.h>
#include<queue>
#include<string.h>
#define mod 1000000007
using namespace std;
const int inf=0x7777777;
const int N=+; int n,m;
long long int a[N];
long long int sum[N*];
void build(int k,int l,int r)
{
sum[k]=;
if(l==r)
{
sum[k]=a[l]%mod;
return ;
}
int mid=l+r>>;
build(k*,l,mid);
build(k*+,mid+,r);
sum[k]=sum[k*]*sum[k*+]%mod; }
__int64 query(int k,int l,int r,int x,int y)
{
__int64 res=;
if(x<=l&&y>=r) return sum[k];
int mid=l+r>>;
if(x<=mid) res*=query(k*,l,mid,x,y)%mod;
if(y>mid) res*=query(k*+,mid+,r,x,y)%mod;
return res%mod;
}
void updata(int k,int l,int r,int x,int y)
{
if(l==r)
{
sum[k]=y%mod;
return;
}
//sum[k]=sum[k]/a[x]*y;
int mid=l+r>>;
if(x<=mid) updata(*k,l,mid,x,y);
else updata(*k+,mid+,r,x,y);
sum[k]=sum[k*]*sum[k*+]%mod; }
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int op,x,y;
scanf("%d",&n);
for(int i=; i<=n; i++) scanf("%I64d",&a[i]);
build(,,n);
scanf("%d",&m);
for(int i=; i<=m; i++)
{
scanf("%d%d%d",&op,&x,&y);
if(!op)
{
__int64 ans=query(,,n,x,y);
printf("%I64d\n",ans%mod);
}
else
{
updata(,,n,x,y);
}
}
}
return ;
}

Multiply game_线段树的更多相关文章

  1. HDU 3074 Multiply game(线段树)

    单点更新,更新时先除去 原来的数,因为有去摸,可以用乘上逆元代替. //================================================================ ...

  2. HDU 3074.Multiply game-区间乘法-线段树(单点更新、区间查询),上推标记取模

    Multiply game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. hdu 3074 Multiply game(模板级线段树)

    离机房关门还有十分钟,这点时间能干些什么?故作沉思地仰望星空,重新捋一下一天的学习进度,或者,砍掉一棵模板级线段树. 纯模板,就是把单点更新,区间求和改为单点更新,区间求积. 1A. #include ...

  4. HDU3074: Multiply game(线段树单点更新,区间查询)

    题目: 传送门 题解:线段树模板题目. 对递归的题目始终理解不好,我的痛啊,在水的题目都要写很长时间. #include <iostream> #include <string.h& ...

  5. HDU 5475(2015 ICPC上海站网络赛)--- An easy problem(线段树点修改)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5475 Problem Description One day, a useless calculato ...

  6. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  7. [java线段树]2015上海邀请赛 D Doom

    题意:n个数 m个询问 每个询问[l, r]的和, 再把[l, r]之间所有的数变为平方(模为9223372034707292160LL) 很明显的线段树 看到这个模(LLONG_MAX为922337 ...

  8. HDU 5475 An easy problem 线段树

    An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. hdu 4578 线段树(标记处理)

    Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) ...

随机推荐

  1. [问题2015S07] 复旦高等代数 II(14级)每周一题(第八教学周)

    [问题2015S07]  设 \(A\) 为 \(n\) 阶复方阵, 证明: 存在 \(n\) 阶非异复对称阵 \(S\), 使得 \(A'=S^{-1}AS\), 即 \(A\) 可通过非异复对称阵 ...

  2. 2. Swift元组|可选值|断言

    1. 元组英文名字 Tuple,将多个数据类型(任意类型)组合成一个数据,与c语言的中的机构体有几分相似,功能也是非常强大的,尤其是在定义请求参数,状态之类的地方经常用到. let http404Er ...

  3. GZFramwork数据库层《四》单据主从表增删改查

    同GZFramwork数据库层<三>普通主从表增删改查 不同之处在于:实例 修改为: 直接上效果: 本系列项目源码下载地址:https://github.com/GarsonZhang/G ...

  4. 分部类(partial)

    一般来说,一个类.结构或接口位于一个源文件中,但某些情况,比如大型项目.特殊部署时,可能需要把一个类.结构或接口放在几个文件中来处理.等到编译时,自动把它们合起来,这就得应用 C# 分部类了. C# ...

  5. Linux中关于安装包的分析。——Arvin

    初接解LINUX的,同样都是for linux,但rpm.tar.gz.deb包还是有很大区别的,这种区别可使安装过程进行不下去.那我们应该下载什么格式的包呢? rpm包-在红帽LINUX.SUSE. ...

  6. python3 字符串相关函数

    python版本 3.5 #Author by Liguangbo#_*_ coding:utf-8 _*_str="i like study python, welcome to my p ...

  7. MyEclipse常用设置

    中文乱码设置:1.window-->preference-->general-->content type然后在<Content Types>中展开每一颗子项,并在< ...

  8. 【转】PDF电子书分享

    http://www.voidcn.com/blog/u013830841/article/p-4343018.html http://www.voidcn.com/blog/u013830841/a ...

  9. 002_kafka_相关术语详细解析

    参考: http://www.cnblogs.com/likehua/p/3999538.html http://kafka.apache.org/documentation.html#getting ...

  10. ABAP之PINYING拼音

    前面说了声母韵母,那么现在来说说ABAP里的拼音——域,数据元素,结构 PINGGUO = 苹果 T-CODE : SE11   如下图 域:是一些特定值的集合,或者某一种特殊用途的集合.如:需要定义 ...