hdu 3074 Multiply game
来源:互联网 发布:有源光纤网络 编辑:程序博客网 时间:2024/05/16 10:34
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
这个题,一道线段树的题,题目的意思容易理解。就是
先输入一个序列,然后 后面m个数据。 第一个为0的话,就
输出第k1 到k2的之间的积,如果是0的话,就把第k 的值改成p
注意积的值对100000007取模, long long 下 lld输出即可
无语的wa点在定义树的结构体的时候,没把节点的值long long
找错 那个心累
#include<iostream>#include<cstring>using namespace std;const int mod=1000000007;struct node{int left,right;long long num;}s[150005];int a[50010];void build(int ll,int rr,int i) //建线段树 {int mm;s[i].left=ll; s[i].right=rr; //左右区间给树的数组 if(ll==rr) //达到叶结点 {s[i].num=a[ll]; //先用数组存下该队的人return ;}mm=(ll+rr)/2; //二分思想build(ll,mm,2*i); //左子树build(mm+1,rr,2*i+1); //右子树s[i].num=(s[2*i].num*s[2*i+1].num)%mod;}void updata(int y,int x,int i) //值 位置 {if(s[i].left==x&&x==s[i].right) {s[i].num=y;return; //到达叶子节点} if(x<=s[2*i].right) updata(y,x,2*i);if(x>=s[2*i+1].left) updata(y,x,2*i+1);s[i].num=(s[2*i].num*s[2*i+1].num)%mod;}long long sum(int ll,int rr,int i) //查询 {int mm;if(s[i].left==ll&&rr==s[i].right) //如果区间覆盖,则直接返回其节点的值 {return s[i].num;}mm=(s[i].left+s[i].right)/2;if(rr<=mm) return sum(ll,rr,2*i); //左子树 if(ll>mm) return sum(ll,rr,2*i+1); //右子树 else {long long a=sum(ll,mm,2*i);long long b=sum(mm+1,rr,2*i+1);return (a*b)%mod; //左右之间 }}int main(){int bbs,k,i,j,n,m,x,y;scanf("%d",&bbs);while(bbs--){scanf("%d",&n);for(i=1;i<=n;i++)scanf("%d",&a[i]);build(1,n,1); //建树scanf("%d",&m);while(m--){scanf("%d%d%d",&k,&x,&y);if(k==0){long long ans=sum(x,y,1);ans=ans%mod;printf("%lld\n",ans);}else updata(y,x,1); //值 和 位置 } }return 0;}
0 0
- 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 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 3074 Multiply game 逆元 树状数组
- 实体类型HR_TimeQuantum不是上下文的一部份
- 优化报表系统结构之报表服务器计算
- 学习OCaml---(0)环境安装
- 英语学习的计划调整
- Unity3D脚本编程--基本概念
- hdu 3074 Multiply game
- 关于SMTP邮件传输协议的一点感悟
- CSP介绍、以及使用CryptoAPI枚举CSP并获取其属性
- MyBatis动态SQL完整版
- 为什么要读这本书
- 一个方便的图片加载框架——ImageViewEx
- cocos2dx 新手引导层
- 网络编程中的read,write函数
- android TabHost小结