Multiply game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2211    Accepted Submission(s): 794

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
 
线段树一直交给队友弄,,好久没练过,自己手打错了好多次,,看来还是要多练练。。
#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(线段树)的更多相关文章

  1. HDU 3074 (线段树+模P乘法)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3074 题目大意:单点更新.维护序列乘法.mod 1000000007. 解题思路: 10000000 ...

  2. 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 ...

  3. hdu 3974 线段树 将树弄到区间上

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. hdu 3436 线段树 一顿操作

    Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  5. hdu 3397 线段树双标记

    Sequence operation Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. hdu 4578 线段树(标记处理)

    Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) ...

  7. hdu 4533 线段树(问题转化+)

    威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Tot ...

  8. hdu 2871 线段树(各种操作)

    Memory Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  9. hdu 4052 线段树扫描线、奇特处理

    Adding New Machine Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. centos7安装phpstudy

    操作系统:CentOS 7 x86_64 SSH登录工具:FinalSHell 2.9.7 一.安装phpstudy 1.下载完整版: wget -c http://lamp.phpstudy.net ...

  2. yii2 基本的增删改查

    一:添加方法 1.1 使用成员属性的方式 save $user_name = $_POST['user_name']; $password = $_POST['password']; //实例化 $u ...

  3. day09-函数讲解

    1.如何定义一个函数 s = '华为加油a' def s_len(): i = 0 for k in s: i += 1 print(i) s_len() 这个函数的功能就是输出字符串的长度.但是他只 ...

  4. bootmem API总结

    bootmem_init()函数执行完成后,linux启动初期的bootmem分配器就初始化完成了,可以调用bootmem提供的API分配内存. 这些API在include/linux/bootmem ...

  5. [原]sencha touch之NavigationView

    还是直接上代码,都是基本的几个容器控件,没什么还说的 Ext.application({ name:'itkingApp', launch:function(){ var view =Ext.crea ...

  6. Java并发之(1):volatile关键字(TIJ21-21.3.3 21.3.4)

    Java并发Java服务器端编程的一项必备技能. ** 1 简介    volatile是java中的一个保留关键字,它在英语中的含义是易变的,不稳定的.volatile像final.static等其 ...

  7. 非常全的API接口查询

    http://www.apix.cn/services/category/3 https://www.showapi.com/ https://www.juhe.cn/docs http://deve ...

  8. SSH的基本操作

    一. 登陆SSH远程控制服务器 我们以192.168.100.42服务器为例. SSH乱码: LANG="zh_CN.GB18030" export LANG=zh_CN.gb23 ...

  9. 16进制转10进制 HDU-1720

    A+B Coming Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. hdu2586&&poj1330 求点间最短距&&最近公共祖先(在线&&离线处理):::可做模板

    How far away ? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...