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. 【20160924】GOCVHelper 图像处理部分(1)

    增强后的图像需要通过图像处理获得定量的值.在实际程序设计过程中,轮廓很多时候都是重要的分析变量.参考Halcon的相关函数,我增强了Opencv在这块的相关功能.      //寻找最大的轮廓     ...

  2. jQuery 添加元素

    jQuery 添加元素 1.append 在被选元素的结尾插入内容 $(document).ready(function(){ $("button").click(function ...

  3. [问题2014S09] 复旦高等代数II(13级)每周一题(第九教学周)

    [问题2014S09]  证明: \(n\) 阶方阵 \(A\) 与所有的 \(A^m\,(m\geq 1)\) 都相似的充分必要条件是 \(A\) 的 Jordan 标准型为 \[\mathrm{d ...

  4. mysql多表查询例子

    [理解方式]先分别找出每个表中查询出来的结果,然后再将两个结果合并. create database test charset utf8 collate utf8_bin;use test;creat ...

  5. 继续Kanzi

    转眼间,Kanzi已经发展到3.3版本了,之前研究过的东西,今天有空下了个版本跟进更新看看有没有什么变化.新的引擎跟以前2.x版本有很大的差别.新引擎增加了很多新功能(包括局部刷新技术),也跟随大潮加 ...

  6. 9----Lua中的面向对象

    什么是面向对象? 使用对象.类.继承.封装.消息等基本概念来进行程序设计 面向对象最重要的两个概念就是:对象和类 对象是系统中用来描述客观事物的一个实体,它是构成系统的一个基本单位 一个对象由一组属性 ...

  7. Criterion & DetachedCriteria

    今天笔记主要是记录笔记,以及代码: criteria: 创建查询接口:createCriteria(class) 查询条件接口:add(各种条件); Restrictions 提供了设置参数的各种接口 ...

  8. 【hdu5973】高精度威佐夫博弈

    题意:输入a, b表示两堆石头数目,威佐夫博弈,问:先手胜负? a, b <= 1e100. 高精度.当a > b时, a = (a-b)*黄金分割比 时是先手败状态.因为a, b < ...

  9. tomcat配置项目的图片路径不在项目下的处理

    <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWA ...

  10. iOS沙盒路径的查看和使用

    1.模拟器沙盒目录 文件都在个人用户名文件夹下的一个隐藏文件夹里,中文叫资源库,他的目录其实是Library. 因为应用是在沙箱(sandbox)中的,在文件读写权限上受到限制,只能在几个目录下读写文 ...