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. python操作adb代码

    adb命令的练习 #!/usr/bin/env python # encoding: utf-8 import os import re nameplt=re.compile("packag ...

  2. openstack环境下的虚拟机通过浮动IP访问后能ping通外网IP不能ping通域名

    1.环境简介 openstack环境下构造Ubuntu系统的VM,VM配置受管子网和自管子网,同时绑定浮动IP 2.通过浮动IP访问VM后,ping www.baidu.com失败,但是通过IP地址p ...

  3. 安装mysql驱动之 mysqlclient 出现的报错处理(ubuntu16.04)

    首先 更新软件! sudo apt-get update 然后尝试安装mysqlclient,报错 后执行下面的步骤 安装mysql驱动之 mysqlclient 出现的报错信息处理 报错1: OSE ...

  4. Effective STL 阅读笔记: Item 4 ~ 5: Call empty instead of checking size() against zero.

    Table of Contents 1 Item 4: Call empty instead of checking size() against zero 2 Item 5: Prefer rang ...

  5. Android网络开启、关闭整理

    package com.my.device_admin.business; import java.lang.reflect.Method; import android.content.Contex ...

  6. Hadoop案例(九)流量汇总案例

    流量汇总程序案例 1.自定义输出 统计手机号耗费的总上行流量.下行流量.总流量(序列化) 1)需求: 统计每一个手机号耗费的总上行流量.下行流量.总流量 2)数据准备 phone_date.txt - ...

  7. [实战]MVC5+EF6+MySql企业网盘实战(8)——文件下载、删除

    写在前面 上篇文章通过iframe实现了文件的无刷新上传.这篇我们将实现文件的下载与删除. 系列文章 [EF]vs15+ef6+mysql code first方式 [实战]MVC5+EF6+MySq ...

  8. Codeforces Round #292 (Div. 1) C - Drazil and Park

    C - Drazil and Park 每个点有两个值Li 和 Bi,求Li + Rj (i < j) 的最大值,这个可以用线段树巧妙的维护.. #include<bits/stdc++. ...

  9. 牛客练习赛19 C-托米航空公司

    思路:轮廓线dp,找bug找死我了. #include<bits/stdc++.h> #define LL long long #define fi first #define se se ...

  10. <c:if></c:if>用法-转载

    <c:if test="value ne, eq, lt, gt,...."> 用法 类别 运算符 算术运算符 + . - . * . / (或 div )和 % (或 ...