Multiply game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2189    Accepted Submission(s):
783

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
#define mod 1000000007
#include<iostream>
using namespace std;
#include<cstdio>
#include<cstring>
#define N 50010
struct Tree{
long long sum;
}tree[N*];/*数组要开到四倍,因为会有许多空节点使用不到*/
int n,t,q,k1,k2,p,x;
int a[N];
void update(int k)
{
int lch=k<<,rch=(k<<)+;/*不知道为甚,宏定义会出错误*/
tree[k].sum=(tree[lch].sum*tree[rch].sum)%mod;
}
void build_tree(int k,int l,int r)
{
int lch=k<<,rch=(k<<)+,mid=(l+r)>>;
if(l==r)
{
tree[k].sum=a[l]%mod;
return ;
}
build_tree(lch,l,mid);
build_tree(rch,mid+,r);
update(k);
}
long long query(int k,int l,int r,int k1,int k2)
{
int lch=k<<,rch=(k<<)+,mid=(l+r)>>;
if(k1<=l&&r<=k2)
{
return tree[k].sum%mod;
}
long long ans=;
if(k1<=mid)
ans=(ans*query(lch,l,mid,k1,k2))%mod;
if(k2>mid)
ans=(ans*query(rch,mid+,r,k1,k2))%mod;
return ans;
}
void change(int k,int l,int r,int pos,int pl)
{
int lch=k<<,rch=(k<<)+,mid=(l+r)>>;
if(l==r)/*一开始加了懒惰标记,结果下传的时候处理的和区间下传一样了,结果错了,改为直接找到单点,再往回更新*/
{
tree[k].sum=pl;
return;
}
if(pos<=mid)
change(lch,l,mid,pos,pl);
else change(rch,mid+,r,pos,pl);
update(k);
}
int main()
{
scanf("%d",&t);
while(t--)
{
memset(tree,,sizeof(tree));
memset(a,,sizeof(a));
scanf("%d",&n);
for(int i=;i<=n;++i)
{
scanf("%d",&a[i]);
}
build_tree(,,n);
scanf("%d",&q);
for(int i=;i<=q;++i)
{
scanf("%d",&x);
if(x==)
{
scanf("%d%d",&k1,&k2);
cout<<query(,,n,k1,k2)<<endl;
}
else
{
scanf("%d%d",&k1,&p);
change(,,n,k1,p);
a[k1]=p;
}
} }
return ;
}
 

线段树 求区间连乘——hdu 3074 Multiply game的更多相关文章

  1. hdu 1754 I Hate It (线段树求区间最值)

    HDU1754 I Hate It Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u D ...

  2. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  3. xdoj-1324 (区间离散化-线段树求区间最值)

    思想 : 1 优化:题意是覆盖点,将区间看成 (l,r)转化为( l-1,r) 覆盖区间 2 核心:dp[i]  覆盖从1到i区间的最小花费 dp[a[i].r]=min (dp[k])+a[i]s; ...

  4. 【线段树求区间第一个不大于val的值】Lpl and Energy-saving Lamps

    https://nanti.jisuanke.com/t/30996 线段树维护区间最小值,查询的时候优先向左走,如果左边已经找到了,就不用再往右了. 一个房间装满则把权值标记为INF,模拟一遍,注意 ...

  5. poj 3264 线段树 求区间最大最小值

    Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same ...

  6. BZOJ 4127: Abs (树链剖分 线段树求区间绝对值之和 带区间加法)

    题意 给定一棵树,设计数据结构支持以下操作 1 u v d 表示将路径 (u,v) 加d(d>=0) 2 u v 表示询问路径 (u,v) 上点权绝对值的和 分析 绝对值之和不好处理,那么我们开 ...

  7. HDU6447 YJJ's Salesman-2018CCPC网络赛-线段树求区间最值+离散化+dp

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门  原题目描述在最下面.  1e5个点,问 ...

  8. 线段树(区间合并)HDU - 1540

    题意:输入n,m,给定n个相互连通的村庄,有m个操作,D x,表示破坏x村庄使其与相邻的两个村庄不相通,R 表示修复上一个被破坏的村庄,与相邻的两个村庄联通.Q x表示与x相连的村庄有多少个. 思路: ...

  9. hdu1166 敌兵布阵(线段树 求区间和 更新点)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

随机推荐

  1. 如何实用便捷的在本地真机调试WEB端HTML5网页

    先简单介绍两款常用但需要一定条件或限制的工具 1.如果你能FQ chrome在32版本后就自带了移动端调度工具,可以在Android直接联调,但唯一遗憾的是,在我大天朝要FQ后才能行的通,我自己试了后 ...

  2. [005] unique_sub_string

    [Description] Given a string, find the largest unique substring. e.g. str[] = "asdfghjkkjhgf&qu ...

  3. mysql 创建数据库的时候选择 utf8 bin 和 utf8 ci的区别

    utf8 ci  不区分大小写: utf8 bin 区分大小写:

  4. 20165301 2017-2018-2 《Java程序设计》第四周学习总结

    20165301 2017-2018-2 <Java程序设计>第四周学习总结 教材学习内容总结 第五章:子类与继承 一个类只能有一个父类,但是可以有若干个子类. 子类的继承性 子类和父类在 ...

  5. ASPLOS'17论文导读——SC-DCNN: Highly-Scalable Deep Convolutional Neural Network using Stochastic Computing

    今年去参加了ASPLOS 2017大会,这个会议总体来说我感觉偏系统和偏软一点,涉及硬件的相对少一些,对我这个喜欢算法以及硬件架构的菜鸟来说并不算非常契合.中间记录了几篇相对比较有趣的paper,今天 ...

  6. Linux命令之dig命令挖出DNS的秘密

    === [初次见面] 我相信使用nslookup的同学一定比使用dig的同学多,所以还是有必要花些时间给大家介绍一下dig的. dig,和nslookup作用有些类似,都是DNS查询工具. dig,其 ...

  7. mvc部署

    权限中加入windows 2008中加入SERVICE,windows2003中加入NETWORK SERVICE

  8. (转载)Linux入门:操作目录和文件的命令

    PATH   每个用户的PATH都是不一样的: PATH中不包含“当前目录”: (1)echo $PATH:显示PATH环境变量: (2)PATH = "$PATH":/home/ ...

  9. Python中列表的各种方法

    列表是Python中一种常用的存储信息的方式,所以要熟练掌握列表的各种方法: 首先我们定义一个列表(name),然后练习里面的各种方法: >>> name = ["Sora ...

  10. pdb-不需要IDE也能调试

    python中有个pdb模块,使python代码也可以像gdb那样进行调试,一般情况下pdb模块可以在代码内直接使用,也可以通过命令行参数的形式添加该模块进行调试(python -m pdb file ...