HDU 3074 (线段树+模P乘法)
题目链接: 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
- #include "iostream"
- #include "string"
- #include "vector"
- #include "cstring"
- #include "fstream"
- #include "cstdio"
- using namespace std;
- #define M 100005
- #define lson l,mid,root<<1
- #define rson mid+1,r,root<<1|1
- #define LL long long
- #define mod 1000000007
- LL ans[M<<];
- void PushUp(int root)
- {
- LL a=ans[root<<]%mod,b=ans[root<<|]%mod;
- ans[root]=(a*b)%mod;
- }
- void build(int l,int r,int root)
- {
- if(l==r)
- {
- scanf("%I64d",&ans[root]);
- return;
- }
- int mid=(l+r)>>;
- build(lson);
- build(rson);
- PushUp(root);
- }
- void update(int p,int value,int l,int r,int root)
- {
- if(l==r)
- {
- ans[root]=value;
- return;
- }
- int mid=(l+r)>>;
- if(p<=mid) update(p,value,lson);
- else update(p,value,rson);
- PushUp(root);
- }
- LL Query(int L,int R,int l,int r,int root)
- {
- if(L<=l&&r<=R) return ans[root]%mod;
- int mid=(l+r)>>;
- LL ret=-;
- if(L<=mid) ret=Query(L,R,lson);
- if(R>mid)
- {
- LL rr=Query(L,R,rson);
- if(ret!=-)
- {
- LL a=ret%mod,b=rr%mod;
- ret=(a*b)%mod;
- }
- else ret=rr;
- }
- return ret;
- }
- int main()
- {
- //freopen("in.txt","r",stdin);
- int n,q,ll,rr,p,k,v,cmd;
- int T;scanf("%d",&T);
- while(T--)
- {
- scanf("%d",&n);
- build(,n,);
- scanf("%d",&q);
- while(q--)
- {
- scanf("%d",&cmd);
- if(cmd==)
- {
- scanf("%d%d",&k,&v);
- update(k,v,,n,);
- }
- if(cmd==)
- {
- scanf("%d%d",&ll,&rr);
- LL ans=Query(ll,rr,,n,);
- printf("%I64d\n",ans%mod);
- }
- }
- }
- return ;
- }
HDU 3074 (线段树+模P乘法)的更多相关文章
- hdu 3074(线段树)
Multiply game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 4578 线段树(标记处理)
Transformation Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others) ...
- 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 ...
- hdu 3974 线段树 将树弄到区间上
Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3436 线段树 一顿操作
Queue-jumpers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu 3397 线段树双标记
Sequence operation Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 4533 线段树(问题转化+)
威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- hdu 2871 线段树(各种操作)
Memory Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 4052 线段树扫描线、奇特处理
Adding New Machine Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
随机推荐
- linux文件描述符open file descriptors与open files的区别
一个文件被打开,也可能没有文件描述符,比如current working diretories,memory mapped files and executable text files ;losf可 ...
- Clr Via C#读书笔记---程序集的加载和反射
#1 加载程序集 Assembly.Load: public class Assembly { public static Assembly Load(AssemblyName assemblyRef ...
- 无废话Android之smartimageview使用、android多线程下载、显式意图激活另外一个activity,检查网络是否可用定位到网络的位置、隐式意图激活另外一个activity、隐式意图的配置,自定义隐式意图、在不同activity之间数据传递(5)
1.smartimageview使用 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...
- JavaScript中判断对象类型方法大全1
我们知道,JavaScript中检测对象类型的运算符有:typeof.instanceof,还有对象的constructor属性: 1) typeof 运算符 typeof 是一元运算符,返回结果是一 ...
- 5-06使用Sql 语句为表添加约束
约束名的命名规则推荐采用:约束类型_约束列. 为用户表添加约束 ALTER TABLE UserInfo ADD CONSTRALNT PK_UserId PRIMATY REY(UserId) CO ...
- php获取文件夹下面的文件列表和文件夹列表
function getDir($dir) { $dirArray[] = NULL; if (false != ($handle = opendir( $dir ))) { $i=0; while ...
- Kmeans聚类算法原理与实现
Kmeans聚类算法 1 Kmeans聚类算法的基本原理 K-means算法是最为经典的基于划分的聚类方法,是十大经典数据挖掘算法之一.K-means算法的基本思想是:以空间中k个点为中心进行聚类,对 ...
- 在Salesforce中创建Web Service供外部系统调用
在Salesforce中可以创建Web Service供外部系统调用,并且可以以SOAP或者REST方式向外提供调用接口,接下来的内容将详细讲述一下用SOAP的方式创建Web Service并且用As ...
- HDU 3586 Information Disturbing 树形DP+二分
Information Disturbing Problem Description In the battlefield , an effective way to defeat enemies ...
- oc中定时器的基本使用
// 时间间隔 调用的对象 调用的方法 用户信息 是否循环 [NSTimer scheduledTimerWithTimeInterval: target:self selector:@select ...