HDU 3074.Multiply game-区间乘法-线段树(单点更新、区间查询),上推标记取模
Multiply game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3224 Accepted Submission(s): 1173
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…
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.
6
1 2 4 5 6 3
3
0 2 5
1 3 7
0 2 5
420
没什么好说的,水题。
代码:
//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-区间乘法-线段树(单点更新、区间查询),上推标记取模的更多相关文章
- HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)
HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...
- HDU 1166 排兵布阵(线段树单点更新)
题意: 给定n个兵营的士兵初始值, 然后有最多40000个操作: 操作一共有两种, 一个是查询给定[a,b]区间兵营的士兵总和. 另一个是增加/减少指定兵营的士兵数目. 输出每次查询的值. 分析: 线 ...
- hdu 1166 敌兵布阵 (线段树单点更新)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) ...
- NYOJ-568/1012//UVA-12299RMQ with Shifts,线段树单点更新+区间查询
RMQ with Shifts 时间限制:1000 ms | 内存限制:65535 KB 难度:3 -> Link1 <- -> Link2 <- 以上两题题意是一样 ...
- 【HDU】1754 I hate it ——线段树 单点更新 区间最值
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 1394 Minimum Inversion Number (线段树 单点更新 求逆序数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题意:给你一个n个数的序列,当中组成的数仅仅有0-n,我们能够进行这么一种操作:把第一个数移到最 ...
- HDU 1166敌兵布阵+NOJv2 1025: Hkhv love spent money(线段树单点更新区间查询)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- hdu 1166 敌兵布阵(线段树单点更新,区间查询)
题意:区间和 思路:线段树 #include<iostream> #include<stdio.h> using namespace std; #define MAXN 500 ...
- HDU 1166 敌兵布阵 (线段树 单点更新)
题目链接 线段树掌握的很差,打算从头从最简单的开始刷一波, 嗯..就从这个题开始吧! #include <iostream> #include <cstdio> #includ ...
随机推荐
- OpenCV---人脸检测
一:相关依赖文件下载 https://github.com/opencv/opencv 二:实现步骤(图片检测) (一)读取图片 image= cv.imread("./d.png&qu ...
- UVA 1650 Number String
https://vjudge.net/problem/UVA-1650 题意:D表示比前一个数打,I表示比前一个数小,?表示不确定 给出一个长为n由D I?组成的字符串,问满足字符串大小要求的n+1的 ...
- GYM 101128 G.Game of Cards(博弈论) 或者 UVALIVE 7278
题目链接:http://codeforces.com/gym/101128/my 如果可以,就看这个人的代码吧,我还不是很懂唉:http://blog.csdn.net/loy_184548/arti ...
- 重构改善既有代码设计--重构手法11:Move Field (搬移字段)
你的程序中,某个字段被其所驻类之外的另一个类更多的用到.在目标类建立一个新字段,修改源字段的所有用户,令它们改用新字段. 动机:在类之间移动状态和行为,是重构过程中必不可少的措施.随着系 ...
- 【Foreign】Melancholy [线段树]
Melancholy Time Limit: 10 Sec Memory Limit: 256 MB Description DX3906星系,Melancholy星上,我在勘测这里的地质情况. 我 ...
- 【BZOJ】2125: 最短路 圆方树(静态仙人掌)
[题意]给定带边权仙人掌图,Q次询问两点间最短距离.n,m,Q<=10000 [算法]圆方树处理仙人掌问题 [题解]树上的两点间最短路问题,常用倍增求LCA解决,考虑扩展到仙人掌图. 先对仙人掌 ...
- NYOJ 35 表达式求值 (字符串处理)
题目链接 描述 ACM队的mdd想做一个计算器,但是,他要做的不仅仅是一计算一个A+B的计算器,他想实现随便输入一个表达式都能求出它的值的计算器,现在请你帮助他来实现这个计算器吧. 比如输入:&quo ...
- antdVG6随记
g6是一个很棒的可视化工具 目前支持开发者搭建属于自己的图,图分析.图应用.图编辑器 图编辑器可以支持多种图例的创建 G6 是一个简单.易用.完备的图可视化引擎,它在高定制能力的基础上,提供了一系列设 ...
- sar命令使用【转】
sar(System Activity Reporter系统活动情况报告)是目前 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告,包括:文件的读写情况.系统调用的使用情 ...
- MySQL5.6.26升级到MySQL5.7.9实战方案【转】
MySQL5.6.26升级到MySQL5.7.9实战方案 转自 MySQL5.6.26升级到MySQL5.7.9实战方案 - 其他网络技术 - 红黑联盟http://www.2cto.com/net/ ...