题目链接http://acm.hdu.edu.cn/showproblem.php?pid=3074

题目大意:单点更新。维护序列乘法。mod 1000000007。

解题思路

1000000007*1000000007~10^18<9*10^18(int64)

所以单步模P乘法可以直接计算。

(a*b)%p=[(a%p)*(b%p)]%p,PushUp维护即可。

Query的rson的时候,要先判下lson是否存在,不存在ret=Query(rson),否则ret=(Query(lson)*Query(rson))%p

  1. #include "iostream"
  2. #include "string"
  3. #include "vector"
  4. #include "cstring"
  5. #include "fstream"
  6. #include "cstdio"
  7. using namespace std;
  8. #define M 100005
  9. #define lson l,mid,root<<1
  10. #define rson mid+1,r,root<<1|1
  11. #define LL long long
  12. #define mod 1000000007
  13. LL ans[M<<];
  14. void PushUp(int root)
  15. {
  16. LL a=ans[root<<]%mod,b=ans[root<<|]%mod;
  17. ans[root]=(a*b)%mod;
  18. }
  19. void build(int l,int r,int root)
  20. {
  21. if(l==r)
  22. {
  23. scanf("%I64d",&ans[root]);
  24. return;
  25. }
  26. int mid=(l+r)>>;
  27. build(lson);
  28. build(rson);
  29. PushUp(root);
  30. }
  31. void update(int p,int value,int l,int r,int root)
  32. {
  33. if(l==r)
  34. {
  35. ans[root]=value;
  36. return;
  37. }
  38. int mid=(l+r)>>;
  39. if(p<=mid) update(p,value,lson);
  40. else update(p,value,rson);
  41. PushUp(root);
  42. }
  43. LL Query(int L,int R,int l,int r,int root)
  44. {
  45. if(L<=l&&r<=R) return ans[root]%mod;
  46. int mid=(l+r)>>;
  47. LL ret=-;
  48. if(L<=mid) ret=Query(L,R,lson);
  49. if(R>mid)
  50. {
  51. LL rr=Query(L,R,rson);
  52. if(ret!=-)
  53. {
  54. LL a=ret%mod,b=rr%mod;
  55. ret=(a*b)%mod;
  56. }
  57. else ret=rr;
  58. }
  59. return ret;
  60. }
  61. int main()
  62. {
  63. //freopen("in.txt","r",stdin);
  64. int n,q,ll,rr,p,k,v,cmd;
  65. int T;scanf("%d",&T);
  66. while(T--)
  67. {
  68. scanf("%d",&n);
  69. build(,n,);
  70. scanf("%d",&q);
  71. while(q--)
  72. {
  73. scanf("%d",&cmd);
  74. if(cmd==)
  75. {
  76. scanf("%d%d",&k,&v);
  77. update(k,v,,n,);
  78. }
  79. if(cmd==)
  80. {
  81. scanf("%d%d",&ll,&rr);
  82. LL ans=Query(ll,rr,,n,);
  83. printf("%I64d\n",ans%mod);
  84. }
  85. }
  86. }
  87. return ;
  88. }

HDU 3074 (线段树+模P乘法)的更多相关文章

  1. hdu 3074(线段树)

    Multiply game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

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

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

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

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

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

  5. hdu 3436 线段树 一顿操作

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

  6. hdu 3397 线段树双标记

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

  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. linux文件描述符open file descriptors与open files的区别

    一个文件被打开,也可能没有文件描述符,比如current working diretories,memory mapped files and executable text files ;losf可 ...

  2. Clr Via C#读书笔记---程序集的加载和反射

    #1 加载程序集 Assembly.Load: public class Assembly { public static Assembly Load(AssemblyName assemblyRef ...

  3. 无废话Android之smartimageview使用、android多线程下载、显式意图激活另外一个activity,检查网络是否可用定位到网络的位置、隐式意图激活另外一个activity、隐式意图的配置,自定义隐式意图、在不同activity之间数据传递(5)

    1.smartimageview使用 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...

  4. JavaScript中判断对象类型方法大全1

    我们知道,JavaScript中检测对象类型的运算符有:typeof.instanceof,还有对象的constructor属性: 1) typeof 运算符 typeof 是一元运算符,返回结果是一 ...

  5. 5-06使用Sql 语句为表添加约束

    约束名的命名规则推荐采用:约束类型_约束列. 为用户表添加约束 ALTER TABLE UserInfo ADD CONSTRALNT PK_UserId PRIMATY REY(UserId) CO ...

  6. php获取文件夹下面的文件列表和文件夹列表

    function getDir($dir) { $dirArray[] = NULL; if (false != ($handle = opendir( $dir ))) { $i=0; while ...

  7. Kmeans聚类算法原理与实现

    Kmeans聚类算法 1 Kmeans聚类算法的基本原理 K-means算法是最为经典的基于划分的聚类方法,是十大经典数据挖掘算法之一.K-means算法的基本思想是:以空间中k个点为中心进行聚类,对 ...

  8. 在Salesforce中创建Web Service供外部系统调用

    在Salesforce中可以创建Web Service供外部系统调用,并且可以以SOAP或者REST方式向外提供调用接口,接下来的内容将详细讲述一下用SOAP的方式创建Web Service并且用As ...

  9. HDU 3586 Information Disturbing 树形DP+二分

    Information Disturbing Problem Description   In the battlefield , an effective way to defeat enemies ...

  10. oc中定时器的基本使用

    // 时间间隔 调用的对象  调用的方法 用户信息 是否循环 [NSTimer scheduledTimerWithTimeInterval: target:self selector:@select ...