HDU 3074 Multiply game(线段树 单点更新)
来源:互联网 发布:网络十大神神兽为什么 编辑:程序博客网 时间:2024/06/05 12:03
Multiply game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2687 Accepted Submission(s): 949
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…
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.
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
161 2 4 5 6 330 2 51 3 70 2 5
Sample Output
240420
Source
2009 Multi-University Training Contest 17 - Host by NUDT
题意:
求线段树区间乘积,有更改操作。
POINT:
LL,别的其实和求和一样。本以为要用什么费马小定理啥的,写着写着发现线段树一次一次更新就行了,区间除以的时候可能适用。水题。
#include <stdio.h>#include <string.h>#include <iostream>using namespace std;#define rt x<<1|1#define lt x<<1const int N = 50000*8;#define LL long longconst LL p = 1000000007;LL sum[N];LL a[N/8];void init(){ }void build(int x,int l,int r){ if(l==r) (sum[x]=a[l])%=p; else { int mid=(l+r)>>1; build(lt,l,mid); build(rt,mid+1,r); (sum[x]=sum[lt]*sum[rt])%=p; }}void change(int x,int l,int r,int i,LL k){ if(l==r&&r==i) (sum[x]=k)%=p; else { int mid=(l+r)>>1; if(i<=mid) change(lt,l,mid,i,k); if(mid<i) change(rt,mid+1,r,i,k); (sum[x]=sum[lt]*sum[rt])%=p; }}LL query(int x,int l,int r,int ll,int rr){ LL ans=1; if(ll<=l&&rr>=r) (ans*=sum[x])%=p; else { int mid=(l+r)>>1; if(ll<=mid) (ans*=query(lt,l,mid,ll,rr))%=p; if(mid<rr) (ans*=query(rt,mid+1,r,ll,rr))%=p; } return ans; }int main(){ int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); init(); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); } build(1,1,n); int q; scanf("%d",&q); while(q--) { int k,k1,k2; scanf("%d %d %d",&k,&k1,&k2); if(k) { change(1,1,n,k1,(LL)k2); } else { LL ans=0; ans=query(1,1,n,k1,k2); printf("%lld\n",ans); } } } return 0;}
阅读全文
0 0
- HDU 3074 Multiply game(线段树 单点更新)
- HDU 3074-Multiply game(线段树:单点更新,区间求积)
- HDU 3074 Multiply game(线段树区间乘积,单点更新)
- HDU - 3074 - Multiply game (线段树-单点更新,区间求积)
- HDU-3074-Multiply game-单点更新
- HDOJ 题目3074 Multiply game(线段树单点更新,区间求乘积)
- hdu 3074 Multiply game (线段树)
- HDU 3074 Multiply game (线段树)
- hdu 3074 Multiply game(线段树)
- hdu 3074 Multiply game(线段树)
- HDU 3074 线段树 Multiply game
- hdu 3074 Multiply game(模板级线段树)
- hdu 3074 Multiply game(线段树模版)
- hdu 3074 Multiply game(线段树模板题) 解题报告
- hdu 1166(线段树,单点更新)
- HDU 1166(线段树单点更新)
- HDU 1394(线段树单点更新)
- HDU--1754(线段树,单点更新)
- PHP之Linux(十)计划任务与备份策略
- 基于Gitlab CI搭建持续集成环境
- 一起学Java_面向对象(3)
- 视图
- 关于事件
- HDU 3074 Multiply game(线段树 单点更新)
- 操作hdfs 出现Unable to load native-hadoop library for your platform...
- 如何开发正确的、精致的、高效的程序
- 机器学习需了解“三大法宝”、、、
- 第二十二章 JAVA眼中的XML--文件写入
- hdu2433 最短路+思维
- HTML表单、HTTP Get与Post杂谈
- Bing It On Kattis
- java泛型通配符理解和使用