Multiply game

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

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
 
Source
 

没什么好说的,水题。

代码:

 //HDU 3074.Multiply game-区间乘法-线段树(单点更新+区间查询)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5e5+;
const ll mod=;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 ll tree[maxn<<]; ll pushup(int rt)
{
tree[rt]=(tree[rt<<]*tree[rt<<|])%mod;
} void build(int l,int r,int rt)
{
if(l==r){
scanf("%lld",&tree[rt]);
return ;
} int m=(l+r)>>;
build(lson);
build(rson);
pushup(rt);
} void update(int pos,ll c,int l,int r,int rt)
{
if(l==r){
tree[rt]=c;
return ;
} int m=(l+r)>>;
if(pos<=m) update(pos,c,lson);
if(pos> m) update(pos,c,rson);
pushup(rt);
} ll query(int L,int R,int l,int r,int rt)
{
if(L>r||l>R) return ;
if(L<=l&&r<=R){
return tree[rt];
} int m=(l+r)>>;
ll ret=;
if(L<=m) ret=(ret*query(L,R,lson))%mod;
if(R> m) ret=(ret*query(L,R,rson))%mod;
return ret;
} int main()
{
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
build(,n,);
int m;
scanf("%d",&m);
for(int i=;i<=m;i++){
int op;
scanf("%d",&op);
if(op==){
int l,r;
scanf("%d%d",&l,&r);
printf("%lld\n",query(l,r,,n,));
}
else{
int pos;ll val;
scanf("%d%lld",&pos,&val);
val=val%mod;
update(pos,val,,n,);
}
}
}
}

HDU 3074.Multiply game-区间乘法-线段树(单点更新、区间查询),上推标记取模的更多相关文章

  1. HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)

    HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...

  2. HDU 1166 排兵布阵(线段树单点更新)

    题意: 给定n个兵营的士兵初始值, 然后有最多40000个操作: 操作一共有两种, 一个是查询给定[a,b]区间兵营的士兵总和. 另一个是增加/减少指定兵营的士兵数目. 输出每次查询的值. 分析: 线 ...

  3. hdu 1166 敌兵布阵 (线段树单点更新)

    敌兵布阵                                                         Time Limit: 2000/1000 MS (Java/Others)  ...

  4. NYOJ-568/1012//UVA-12299RMQ with Shifts,线段树单点更新+区间查询

    RMQ with Shifts 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 ->  Link1  <- -> Link2  <- 以上两题题意是一样 ...

  5. 【HDU】1754 I hate it ——线段树 单点更新 区间最值

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  6. HDU 1394 Minimum Inversion Number (线段树 单点更新 求逆序数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题意:给你一个n个数的序列,当中组成的数仅仅有0-n,我们能够进行这么一种操作:把第一个数移到最 ...

  7. HDU 1166敌兵布阵+NOJv2 1025: Hkhv love spent money(线段树单点更新区间查询)

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

  8. hdu 1166 敌兵布阵(线段树单点更新,区间查询)

    题意:区间和 思路:线段树 #include<iostream> #include<stdio.h> using namespace std; #define MAXN 500 ...

  9. HDU 1166 敌兵布阵 (线段树 单点更新)

    题目链接 线段树掌握的很差,打算从头从最简单的开始刷一波, 嗯..就从这个题开始吧! #include <iostream> #include <cstdio> #includ ...

随机推荐

  1. K8S Link

    https://www.cnblogs.com/linuxk/p/9783510.html https://www.cnblogs.com/fengzhihai/p/9851470.html

  2. jquery validate submitHandler 提交导致死循环

    dom对像的提交form.submit();和jquery对像的提交$('').submit();功能上是没有什么区别的.但是如果用了jquery validate插件,提交时这二个就区别大了.$(' ...

  3. Java集合框架(list,Queue)

    List和Queue都继承自Collection接口 list常规用法 List判断两个对象相等的标准:equals方法返回true class A2 { public boolean equals( ...

  4. 重构改善既有代码设计--重构手法14:Hide Delegate (隐藏委托关系)

    客户通过一个委托类来调用另一个对象.在服务类上建立客户所需的所有函数,用以隐藏委托关系. 动机:封装即使不是对象的最关机特性,也是最关机特性之一.“封装”意味着每个对象都应该少了解系统的其他部分.如此 ...

  5. IIS 网站日志分析

    最近由于ADSL代理总出问题,导致爬虫服务器总被目标网站封,由于请求内容总是空,前端APP获取不到想要的内容就一直刷新,导致爬虫服务器请求更加繁忙. 爬虫服务器每执行完一个流程,都会给统计服务器Pos ...

  6. [php]http的状态码

    1.分类 100~199 表示成功接受请求,要求客户端继续提交下一次请求才能完成整个过程处理. 200~299 表示成功接收请求并已完成整个处理过程,常用200 300~399 为完成请求,客户需进一 ...

  7. 【BZOJ】1468: Tree(POJ1741) 点分治

    [题意]给定带边权树,求两点距离<=k的点对数.n<=40000. [算法]点分治 [题解]对于一个区域,选择其重心x作为根,则划分出来的每棵子树都是子区域,可以证明至多划分log n次( ...

  8. CodeForces - 1003D

    Polycarp has nn coins, the value of the ii-th coin is aiai. It is guaranteed that all the values are ...

  9. vue-cli使用说明

    一.安装npm install -g vue-cli 推荐使用国内镜像 先设置cnpm npm install -g cnpm --registry=https://registry.npm.taob ...

  10. 阿里云一键web环境包

    下载地址:https://files.cnblogs.com/files/wordblog/af3a48ef-3a13-479e-85c9-ead61173126c.zip 先把安装包传到服务器上用w ...