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. 项目开发 -- ZFS容量分配

    存储池 allocated 池中已实际分配的存储空间量.该属性也可通过其简短列名alloc来引用. capacity 已用的池空间百分比.此属性也可通过其简短列名cap来引用. dedupratio ...

  2. VueJS 轻松支持 JSX 配置

    使用: babel-preset-vue-app TODO

  3. SQLite3数据库的操作

    数据库的操作 我们在这个项目中使用的是SQLITE3数据库软件. 通过使用SQLITE3进行创建数据库,创建表,插入记录,查询记录,更新记录,关闭数据库等操作来实现将相应的数据存入数据库中. 打开数据 ...

  4. React 16 源码瞎几把解读 【三 点 一】 把react组件对象弄到dom中去(矛头指向fiber,fiber不解读这个过程也不知道)

    一.ReactDOM.render 都干啥了 我们在写react的时候,最后一步肯定是 ReactDOM.render( <div> <Home name="home&qu ...

  5. Redis 启动警告解决【转】

    [root@centos224]# service redisd start :M Nov :: (it was originally set to ). _._ _.-``__ ''-._ _.-` ...

  6. 设置网卡IP,还每次都挨个地址输入吗?批处理一下【转】

    1.设置网卡ip,子网掩码和默认网关,注意修改网卡名称,跟本地连接汇总的网卡名称保持一直 netsh interface ip set address "以太网" static 1 ...

  7. tyvj P1050 最长公共子序列

    题目链接:http://tyvj.cn/p/1050 题解: 裸题,只是为了测试LCS模板写对没有…… #include<cstdio> #include<cstring> # ...

  8. Java Number类和Math类

    Java Number类 一般的,当需要使用数字的时候,我们通常使用内置数据类型,如:byte.int.long.double等. 然而,在实际开发过程中,我们经常会遇到需要使用对象,而不是内置数据类 ...

  9. 安装 jupyter notebook 出现 ModuleNotFoundError: No module named 'markupsafe._compat' 错误

    使用 python -m pip install jupyter 安装完成 jupyter notebook 之后,在命令行界面输入 "jupyter notebook "指令打开 ...

  10. c++ primer 6 语句

    没什么重要的东西,异常处理在17章再讲吧