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
 
线段树一直交给队友弄,,好久没练过,自己手打错了好多次,,看来还是要多练练。。
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. #include <iostream>
  5. using namespace std;
  6. typedef long long LL;
  7. const int N = ;
  8. const LL mod =;
  9. LL a[N];
  10. struct Tree{
  11. int l,r,mid;
  12. LL v;
  13. }tree[N<<];
  14. void build(int l,int r,int idx){
  15. tree[idx].l = l;
  16. tree[idx].r = r;
  17. tree[idx].mid = (l+r)>>;
  18. if(l==r){
  19. tree[idx].v=a[l];
  20. return;
  21. }
  22. build(l,tree[idx].mid,idx<<);
  23. build(tree[idx].mid+,r,idx<<|);
  24. tree[idx].v =(tree[idx<<].v%mod)*(tree[idx<<|].v%mod)%mod;
  25. }
  26. void update(int pos,LL v,int idx){
  27. if(tree[idx].l==tree[idx].r){
  28. tree[idx].v = v;
  29. return;
  30. }
  31. if(pos<=tree[idx].mid) update(pos,v,idx<<);
  32. else update(pos,v,idx<<|);
  33. tree[idx].v =(tree[idx<<].v%mod)*(tree[idx<<|].v%mod)%mod;
  34. }
  35. LL query(int l,int r,int idx){
  36. if(tree[idx].l==l&&tree[idx].r==r){
  37. return tree[idx].v%mod;
  38. }
  39. if(r<=tree[idx].mid) return query(l,r,idx<<)%mod;
  40. else if(l>tree[idx].mid) return query(l,r,idx<<|)%mod;
  41. else return (query(l,tree[idx].mid,idx<<)%mod)*(query(tree[idx].mid+,r,idx<<|)%mod)%mod;
  42. }
  43. int main()
  44. {
  45. int n;
  46. int tcase;
  47. scanf("%d",&tcase);
  48. while(tcase--){
  49. scanf("%d",&n);
  50. for(int i=;i<=n;i++){scanf("%lld",&a[i]);}
  51. build(,n,);
  52. int Q;
  53. scanf("%d",&Q);
  54. while(Q--){
  55. int a,b,c;
  56. scanf("%d%d%d",&a,&b,&c);
  57. if(a==){
  58. query(b,c,);
  59. printf("%lld\n",query(b,c,));
  60. }else update(b,(LL)c,);
  61. }
  62. }
  63. return ;
  64. }

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. iOS SDK中使用NSXMLParser解析XML(iphone网络篇三)

    iOS SDK的NSXMLParser解析XML文档是事件驱动模式的,即采用SAX方式来解析XML格式文档.NSXMLParser在处理XML文档的过程中当遇到一些要素(元素.属性.CDATA块.评论 ...

  2. 662. Maximum Width of Binary Tree

    https://leetcode.com/problems/maximum-width-of-binary-tree/description/ /** * Definition for a binar ...

  3. input type=file输入框

    <div class="row"> <!--选择图片按钮--> <div class="col-xs-12" align=&quo ...

  4. 使用HTTP协议访问网路

    使用HTTP协议访问网路 一.使用HttpURLConnection //new一个URL对象 URL url = new URL("http://www.qq.com");//千 ...

  5. java以正确的方式停止线程

    java线程停止可以说是非常有讲究的,看起来非常简单,但是也要做好一些防范措施,一般停止一个线程可以使用Thread.stop();来实现,但是最好不要用,因为他是不安全的. 大多数停止线程使用Thr ...

  6. .net core 项目加载提示项目文件不完整缺少预期导入的解决办法

    今天把在远端的仓库的代码在另一台电脑上拷贝下来,电脑上.net core 环境也已经安装了,但是发现有几个项目没有加载成功,然后重新加载项目,vs2017却提示 项目文件不完整,缺少预期导入 查看错误 ...

  7. 【精彩回顾】第二届微医前端技术沙龙(附PPT下载)

    5 月 25 日,以「无界」为主题的第二届微医前端技术沙龙成功举办.本届沙龙的演讲题目涵盖了前端技术几个主要的应用场景,包括服务端.桌面端以及跨平台的开发.最近几年前端技术发展非常快,各种可以提高开发 ...

  8. 试水新的Angular4 HTTP API

    本文来自网易云社区 作者:梁月康 原文:https://netbasal.com/a-taste-from-the-new-angular-http-client-38fcdc6b359b Angul ...

  9. IOS开发学习笔记041-UITableView总结1

    一.UITableView的常用属性 1.分割线 // 分割线 self.tableView.separatorColor = [UIColorredColor]; // 隐藏分割线 self.tab ...

  10. IOS架构

    iPhone OS(现在叫iOS)是iPhone, iPod touch 和 iPad 设备的操作系统. 1,Core OS: 是用FreeBSD和Mach所改写的Darwin, 是开源.符合POSI ...