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 ...
随机推荐
- configParser模块详谈
前言 使用配置文件来灵活的配置一些参数是一件很常见的事情,配置文件的解析并不复杂,在python里更是如此,在官方发布的库中就包含有做这件事情的库,那就是configParser configPars ...
- Codeforces Round #443 (Div. 2) C 位运算
C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #464 (Div. 2) A Determined Cleanup
A. Love Triangle time limit per test1 second memory limit per test256 megabytes Problem Description ...
- ZOJ Monthly, January 2018 训练部分解题报告
A是水题,此处略去题解 B - PreSuffix ZOJ - 3995 (fail树+LCA) 给定多个字符串,每次询问查询两个字符串的一个后缀,该后缀必须是所有字符串中某个字符串的前缀,问该后缀最 ...
- 手机端sticker布局,底部按钮在屏幕底部
<template> <div class="product-detail-container"> <div class="detail&q ...
- exkmp略解
推导 ext[i]表示母串s[i..lens]和子串t[1..lent]的最长公共前缀. nxt[i]表示t[i..lent]和t[1..lent]的最长公共前缀. 假设ext[1..k]已经算好,现 ...
- hdu3366 Count the string
考虑dp[i]代表前缀s[1...i]出现的次数,必定有dp[nxt[i]] += dp[i] 倒着推就是了 #include <iostream> #include <cstrin ...
- 云中Active Directory是如何工作的?
[TechTarget中国原创] 微软公司1999年在Windows Server 2000中引入Active Directory功能.后期的Windows Server版本中陆续进行改善提升,Win ...
- python 学习分享-面向对象2
面向对象进阶 静态方法 一种普通函数,就位于类定义的命名空间中,它不会对任何实例类型进行操作.使用装饰器@staticmethod定义静态方法.类对象和实例都可以调用静态方法: class Foo: ...
- node中fileSystem改promise
请注意,fs的大部分函数回调只会返回一个error参数,所以只要判断error为false的情况下就返回成功,无论有没有第二个参数. 另外exists需要单独包装,因为第一个参数就代表返回内容 con ...