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. for循环+canvas实现黑客帝国矩形阵

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  2. 51nod 1202 不同子序列个数(计数DP)

    1202 子序列个数 基准时间限制:1 秒 空间限制:131072 KB 分值: 40      子序列的定义:对于一个序列a=a[1],a[2],......a[n].则非空序列a'=a[p1],a ...

  3. datatime来计算代码段运行时长

    小知识点:编程中一般都是先乘后除,这样结果更为精确 先定义 DataTime startTime = DataTime.Now; 中间是运行代码 最后TimeSpan ts = DataTime.No ...

  4. (ADO.NET)SqlCommand参数化查询

    string strcon = "Persist Security Info=False;User id=sa;pwd=lovemary;database=student;server=(l ...

  5. java流、文件以及IO

    读写文件 一个流被定义为一个数据序列.输入流用于从源读取数据,输出流用于向目标写数据. 输入流和输出流的类层次图. FileInputStream FileInputStream用于从文件中读取数据, ...

  6. 微信SSL证书更换的检查与安装方法

    Ubuntu, Debian 查看根证书 确认操作系统上,是否存在以下文件: /etc/ssl/certs/DigiCert_Global_Root_CA.pem /etc/ssl/certs/Bal ...

  7. vrpie在Visio Studio 中无法调试的问题

    最近这这几天一直在研究vrpie,之前不能调试,一调试就出问题,打开那个生成的htm文件是没问题的,最初的解决方法是不通过调试来打可那个htm页面,但是这样比较麻烦,因为经常需要和服务器交互,就只能用 ...

  8. c++ 吕凤翥 第六章 类和对象(二)

    c++ 吕凤翥 第六章 类和对象(二) 指针   引用  和数组 一:对象指针和对象引用 1.指向类的成员的指针 分为指向成员变量和指向成员函数两种指针 成员变量的格式:     类型说明符  类名: ...

  9. Halcon17 Linux 下载

    Halcon17 Linux 下载地址:http://www.211xun.com/download_page_10.html HALCON 17 是一套机器视觉图像处理库,由一千多个算子以及底层的数 ...

  10. win8中写好的程序,在win7中没办法运行

     没有安装相应版本的,net framework win8自带4.0 win7自带2.0 所以4.0及其以上的程序在win7跑必须安装4.0及其以上版本的framework