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

时间:2022-09-04 11:29:17

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&period;1166 敌兵布阵 &lpar;线段树 单点更新 区间查询&rpar;

    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&sol;1012&sol;&sol;UVA-12299RMQ with Shifts,线段树单点更新&plus;区间查询

    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敌兵布阵&plus;NOJv2 1025&colon; 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. spring4&plus;hibernate4&plus;struts2项目整合的步骤及注意事项

    首先,在整合框架之前,我们需要知道Spring框架在普通Java project和Web project中是略有不同的. 这个不同地方就在于创建IOC容器实例的方式不同,在普通java工程中,可以在m ...

  2. 学习SAP HANA SQL

      学习SAP HANA SQL 语句(创建 EMP,DEPT,BONUS 和 SALGRADE测试表)--像学Oracle一样学习SAP HANA 标签: sap测试oraclesqltableda ...

  3. Apache与Tomcat的整合

    一 Apache与Tomcat比较联系 apache支持静态页,tomcat支持动态的,比如servlet等. 一般使用apache+tomcat的话,apache只是作为一个转发,对jsp的处理是由 ...

  4. js基础篇——call&sol;apply、arguments、undefined&sol;null

    a.call和apply方法详解 call方法: 语法:call([thisObj[,arg1[, arg2[,   [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象 ...

  5. main&lpar;&rpar;和&lowbar;tmain&lpar;&rpar;有什么区别

    用过C的人都知道每一个C的程序都会有一个main(),但有时看别人写的程序发现主函数不是int main(),而是int _tmain(),而且头文件也不是<iostream.h>而是&l ...

  6. &period;Net Core 读取appsettings&period;json的配置

    在.net core中是没有*.config 文件的 配置文件都是*.json 1.在project.json里下面这行代码 "Microsoft.Extensions.Options.Co ...

  7. angularjs-1&period;3代码学习 模块

    花了点时间,阅读了下angularjs的源码.本次先从模块化开始. angular可以通过module的api来实现前端代码的模块化管理.跟define类似.但不具备异步加载脚本的功能.先从最基本的m ...

  8. Perl正则表达式超详细教程

    前言 想必学习perl的人,对基础正则表达式都已经熟悉,所以学习perl正则会很轻松.这里我不打算解释基础正则的内容,而是直接介绍基础正则中不具备的但perl支持的功能.关于基础正则表达式的内容,可参 ...

  9. android 应用商店

    下面更多 http://wiki.youmi.net/Wiki/PromotionChannelIDs 小米 http://market.xiaomi.com/dev安智市场 http://dev.a ...

  10. linux磁盘已满,文件占用情况

    du -sh /data0/* 如上,/data0/* 表示查看data0文件夹下各个目录的磁盘占用情况 df -h 查看总的磁盘占比