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. 2016年江西理工大学C语言程序设计竞赛(高级组)

    问题 A: jxust 解法:争议的问题(是输入整行还是输入字符串),这里倾向输入字符串,然后判断是否含有jxust就行 #include<bits/stdc++.h> using nam ...

  2. HDU1848 Fibonacci again and again SG函数

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  3. How To Use DBLink In Oracle Forms 6i

    You want to connect multiple databases in oracle forms to perform certain tasks, for example you nee ...

  4. How to generate a random number in R

    Generate a random number between 5.0 and 7.5x1 <- runif(1, 5.0, 7.5) # 参数1表示产生一个随机数x2 <- runif ...

  5. RPM安装rabbitMQ

    系统使用的是centos 7 - minimal 建立用户和组: # groupadd rabbitmq # useradd rabbitmq -g rabbitmq 在安装rabbitMQ之前需要先 ...

  6. C语言面试题(三)

    这篇主要聚焦在排序算法,包括常见的选择排序,插入排序,冒泡排序,快速排序.会对这四种排序的时间复杂度和空间复杂度进行探究. a.选择排序 int main(int argc,char **argv){ ...

  7. HDU 5775 Bubble Sort(冒泡排序)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  8. Linux命令行与命令

    Linux命令行与命令   作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Linux的命令是很重要的工具,也往往是初学者最大的瓶 ...

  9. Hibernate关联映射之延迟加载

    什么事延迟加载?   当真正需要数据时才执行SQL语句,其本意是减少不必要的性能开销! 之前提到过一个延迟加载的例子: load();结果集不能为空 当真正去打印对象属性时,sql语句才执行! hib ...

  10. iOS - Frame 项目架构

    前言 iOS 常见的几种架构: 标签式 Tab Menu 列表式 List Menu 抽屉式 Drawer 瀑布式 Waterfall 跳板式 Springborad 陈列馆式 Gallery 旋转木 ...