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 ...
随机推荐
- shell 脚本判断linux 的发行版本
原文vi ./Get_Dist_Name.sh #!/bin/bash Get_Dist_Name() { if grep -Eqii "CentOS" /etc/issue || ...
- python 获取外网地址
def get_ip(): try: url = "http://cn.bing.com/search?q=ip&go=%E6%8F%90%E4%BA%A4&qs=n& ...
- springboot创建maven多模块项目
SpringBoot创建maven多模块项目 项目结构 该项目名称为springboot-maven-multi,由springboot-maven-multi.user-dao.user-domai ...
- 2015/11/1用Python写游戏,pygame入门(1):pygame的安装
这两天学习数据结构和算法,有时感觉并不如直接做项目来的有趣.刚刚学完python的基本使用,现在刚好趁热打铁做个小项目. 由于本人一直很想制作一款游戏,就想使用Python制作一个基础的游戏.搜了一下 ...
- html跑马灯效果
实现跑马灯的方法很多,其中最简单的是采用一句Html代码来实现,我们在需要出现跑马灯效果的地方插入“<marquee>滚动的文字</marquee>”语句,它的效果如下所示: ...
- LintCode 532: Reverse Pairs
LintCode 35: Reverse Linked List 题目描述 翻转一个链表. 样例 给出一个链表1->2->3->null,这个翻转后的链表为3->2->1 ...
- 【有上下界网络流】【ZOJ】2314 Reactor Cooling
[算法]有上下界网络流-无源汇(循环流) [题解]http://www.cnblogs.com/onioncyc/p/6496532.html //未提交 #include<cstdio> ...
- webgote的例子(2)Sql注入(SearchGET)
Sql注入(Search/GET) 大家好!!! 现如今web服务在我们的网络上遍地都是,各个终端设备成为我们看不见的客户,web服务也成为公司的招牌.80 443为我们展现的视角也是多姿多彩但背后新 ...
- Google Gapps – Download Gapps for Android【转】
http://wiki.rootzwiki.com/Google_Apps http://productforums.google.com/forum/#!forum/apps http://www. ...
- Elasticsearch5.0 安装问题集锦【转】
转自 Elasticsearch5.0 安装问题集锦 - 代码&优雅着&生活 - 博客园http://www.cnblogs.com/sloveling/p/elasticsearch ...