hdu 3074(线段树)
Multiply game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2211 Accepted Submission(s): 794
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…
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.
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.
6
1 2 4 5 6 3
3
0 2 5
1 3 7
0 2 5
420
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
const int N = ;
const LL mod =;
LL a[N];
struct Tree{
int l,r,mid;
LL v;
}tree[N<<];
void build(int l,int r,int idx){
tree[idx].l = l;
tree[idx].r = r;
tree[idx].mid = (l+r)>>;
if(l==r){
tree[idx].v=a[l];
return;
}
build(l,tree[idx].mid,idx<<);
build(tree[idx].mid+,r,idx<<|);
tree[idx].v =(tree[idx<<].v%mod)*(tree[idx<<|].v%mod)%mod;
}
void update(int pos,LL v,int idx){
if(tree[idx].l==tree[idx].r){
tree[idx].v = v;
return;
}
if(pos<=tree[idx].mid) update(pos,v,idx<<);
else update(pos,v,idx<<|);
tree[idx].v =(tree[idx<<].v%mod)*(tree[idx<<|].v%mod)%mod;
}
LL query(int l,int r,int idx){
if(tree[idx].l==l&&tree[idx].r==r){
return tree[idx].v%mod;
}
if(r<=tree[idx].mid) return query(l,r,idx<<)%mod;
else if(l>tree[idx].mid) return query(l,r,idx<<|)%mod;
else return (query(l,tree[idx].mid,idx<<)%mod)*(query(tree[idx].mid+,r,idx<<|)%mod)%mod;
}
int main()
{
int n;
int tcase;
scanf("%d",&tcase);
while(tcase--){
scanf("%d",&n);
for(int i=;i<=n;i++){scanf("%lld",&a[i]);}
build(,n,);
int Q;
scanf("%d",&Q);
while(Q--){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a==){
query(b,c,);
printf("%lld\n",query(b,c,));
}else update(b,(LL)c,);
}
}
return ;
}
hdu 3074(线段树)的更多相关文章
- HDU 3074 (线段树+模P乘法)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3074 题目大意:单点更新.维护序列乘法.mod 1000000007. 解题思路: 10000000 ...
- hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)
Weak Pair Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- hdu 3974 线段树 将树弄到区间上
Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3436 线段树 一顿操作
Queue-jumpers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu 3397 线段树双标记
Sequence operation Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 4578 线段树(标记处理)
Transformation Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others) ...
- hdu 4533 线段树(问题转化+)
威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- hdu 2871 线段树(各种操作)
Memory Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 4052 线段树扫描线、奇特处理
Adding New Machine Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
随机推荐
- docker时区正常,但java获得的时间早了8小时解决方法
我解决容器时区的方法是挂载宿主机的/etc/localtime 到容器的/etc/localtime,这时输入date命令容器时区显示正常,但是跑在容器中的java项目取到的时间却早了8小时. 查阅相 ...
- java的类加载器体系结构和双亲委派机制
类加载器将字节码文件加载到内存中,同时在方法区中生成对应的java.land.class对象 作为外部访问方法区的入口. 类加载器的层次结构: 引导类加载器<-------------扩展类加 ...
- 单例模式【python】
在python中,如需让一个类只能创建一个实例对象,怎么能才能做到呢? 思路:1.通过同一个类创建的不同对象,都让他们指向同一个方向. 2.让个类只能创建唯一的实例对象. 方法:用到 _ _new ...
- python3与django中@property详解
django提供了内置装饰器 @staticmethod\@classmethod\property 在OSQA中,@property的使用频率是非常高的.下面就是它的使用方法: @property ...
- IBOutletCollection 索引获取顺序问题
在sb中绑定了一个IBOutletCollection后,根据索引获取元素发现和自己拖线时的顺序不同,有时又会根据顺序,不知道是xcode的bug还是本身就是无序的. 在使用的时候直接排序: - (v ...
- Java之基于Apache jar包的FTPClient上传
首先,准备工作: http://pan.baidu.com/s/1dD1Utwt 从以上链接下载Apache的jar包,并将其复制到工程的WEB-INF下的lib包里,在此,准备工作就已经完成了. 具 ...
- 1、IOS学习计划
2015年12月10日 -- 2015年12月27日(一共3个周末,12个个工作日) 1.斯坦福公开课(IOS7应用开发) 一共18节课程,通过视频和demo建立感觉 2.千峰的OC课程 一共25节课 ...
- hnust 懒人多动脑
问题 F: 懒人得多动脑 时间限制: 1 Sec 内存限制: 128 MB提交: 93 解决: 30[提交][状态][讨论版] 题目描述 小D的家A和学校B都恰好在以点F为焦点的双曲线上,而小D每 ...
- github 客户端总是登录失败,提示密码错误
把输入法调成英文即可!!
- http的一些知识
TCP/IP协议分层 应用层 TFP DNS DNS域名解析的过程 在浏览器DNS缓存中搜索 读取系统的hosts文件,查找其中是否有对应的ip 向本地配置的首选DNS服务器发起域名解析请求 HTTP ...