题意:求所有自己的最小公倍数的和。 该集合是  2^ai  * 3^bi

思路:线段树。 线段树中存的是  【3^b * f(b)】   f(b)表示 因子3 的最小公倍数3的部分  为 3^b的个数  那么从小到大枚举a  对于当前的  ab  ,  如果之前的b小于当前的b  那么最小公倍数就为  (2^a) *  (3^b)   个数 就为 2^x     x表示a  b 都小于当前a b的个数 。  大于的部分 就直接是  2^a   * 线段树上【b,max】的和。   求好当前更新进去,对于 【b,max】 区间 直接乘2 (表示当前这个b可选可不选) 。       b位置加上(2^x)  * (3^b) 的值即可(当前b被选为最大的b时的个数)。

#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include <iostream>
#define lson i<<1
#define rson i<<1|1
#define LL long long
#define N 100050
#define MOD 1000000007
using namespace std;
int cnt[N*],val[N*],sum[N*],mul[N*];
int mypow(int a,int b)
{
int res=;
while(b)
{
if(b&)
res=(LL)res*a%MOD;
a=(LL)a*a%MOD;
b>>=;
}
return res;
}
int qa[N],qb[N];
void build(int l,int r,int i)
{
cnt[i]=sum[i]=;
mul[i]=;
if(l==r)
{
val[i]=mypow(,qb[l]);
return ;
}
int mid=(l+r)>>;
build(l,mid,lson);
build(mid+,r,rson);
}
void pushdown(int i)
{
if(mul[i]!=)
{
mul[lson]=(LL)mul[lson]*mul[i]%MOD;
mul[rson]=(LL)mul[rson]*mul[i]%MOD;
sum[lson]=(LL)sum[lson]*mul[i]%MOD;
sum[rson]=(LL)sum[rson]*mul[i]%MOD;
mul[i]=;
}
}
void pushup(int i)
{
cnt[i]=cnt[lson]+cnt[rson];
sum[i]=(sum[lson]+sum[rson])%MOD;
}
void update(int l,int r,int pl,int pr,int type,int va,int i)
{
if(l>=pl&&r<=pr)
{
if(type==)
{
mul[i]=(LL)mul[i]*va%MOD;
sum[i]=(LL)sum[i]*va%MOD;
}else
{
cnt[i]++;
sum[i]+=(LL)val[i]*va%MOD;
if(sum[i]>=MOD)sum[i]-=MOD;
}
return ;
}
pushdown(i);
int mid=(l+r)>>;
if(mid>=pl)update(l,mid,pl,pr,type,va,lson);
if(pr>mid)update(mid+,r,pl,pr,type,va,rson);
pushup(i);
}
int query(int l,int r,int pl,int pr,int type,int i)
{
if(l>=pl&&r<=pr)
{
if(type==)return sum[i];
else return cnt[i];
}
pushdown(i);
int mid=(l+r)>>;
int tmp=;
if(pl<=mid)tmp+=query(l,mid,pl,pr,type,lson);
if(pr>mid)tmp+=query(mid+,r,pl,pr,type,rson);
if(tmp>=MOD)tmp-=MOD;
return tmp;
}
struct node
{
int a,b;
}s[N];
bool cmp(node a,node b)
{
return a.a<b.a;
}
int main() {
int n;
while(scanf("%d",&n)!=EOF)
{
int taila,tailb;
taila=tailb=;
for(int i=;i<n;++i)
{
scanf("%d%d",&s[i].a,&s[i].b);
qa[taila++]=s[i].a;
qb[tailb++]=s[i].b;
}
sort(s,s+n,cmp);
sort(qa,qa+taila);
sort(qb,qb+tailb);
taila=unique(qa,qa+taila)-qa;
tailb=unique(qb,qb+tailb)-qb;
int maxn=tailb-;
build(,maxn,);
int ans=;
for(int i=;i<n;++i)
{
int x=lower_bound(qb,qb+tailb,s[i].b)-qb;
int tmp=(LL)mypow(,s[i].a)*mypow(,s[i].b)%MOD;
int cc=;
if(x>)
{
cc=query(,maxn,,x-,,);
tmp=(LL)tmp*mypow(,cc)%MOD;
}
int tmp2=(LL)mypow(,s[i].a)*query(,maxn,x,maxn,,)%MOD;
tmp+=tmp2;
if(tmp>=MOD)tmp-=MOD;
ans+=tmp;
if(ans>=MOD)ans-=MOD;
// printf("::%d %d\n",x,maxn);
update(,maxn,x,maxn,,,);
update(,maxn,x,x,,mypow(,cc),);
}
printf("%d\n",(ans%MOD+MOD)%MOD);
} return ;
}

HDU 4913 Least common multiple(2014 Multi-University Training Contest 5)的更多相关文章

  1. HDU 4913 Least common multiple

    题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...

  2. ACM学习历程—HDU 3092 Least common multiple(数论 && 动态规划 && 大数)

    Description Partychen like to do mathematical problems. One day, when he was doing on a least common ...

  3. hdu 5003 模拟水题 (2014鞍山网赛G题)

    你的一系列得分 先降序排列 再按0.95^(i-1)*ai 这个公式计算你的每一个得分 最后求和 Sample Input12530 478Sample Output984.1000000000 # ...

  4. 背包系列练习及总结(hud 2602 && hdu 2844 Coins && hdu 2159 && poj 1170 Shopping Offers && hdu 3092 Least common multiple && poj 1015 Jury Compromise)

    作为一个oier,以及大学acm党背包是必不可少的一部分.好久没做背包类动规了.久违地练习下-.- dd__engi的背包九讲:http://love-oriented.com/pack/ 鸣谢htt ...

  5. 千寻浏览器 1.0 Beta 1(524)(2014年5月27日)

    千寻浏览器--又一款新生浏览器今天进入各位浏览迷的视野.千寻浏览器基于IE内核,据传是由百度浏览器的上海团队操刀,在功能定位上,与目前的QQ浏览器有些相似. 千寻来自官方的解释:寻,追寻,探索,又是古 ...

  6. HDU 3416 Marriage Match IV (最短路径,网络流,最大流)

    HDU 3416 Marriage Match IV (最短路径,网络流,最大流) Description Do not sincere non-interference. Like that sho ...

  7. ( 2018 Multi-University Training Contest 2)

    2018 Multi-University Training Contest 2) HDU 6311 Cover HDU 6312 Game HDU 6313 Hack It HDU 6314 Mat ...

  8. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  9. HDU——1019Least Common Multiple(多个数的最小公倍数)

    Least Common Multiple Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

随机推荐

  1. JavaScript俄罗斯方块

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  2. [Effective JavaScript 笔记]第65条:不要在计算时阻塞事件队列

    第61条解释了异步API怎样帮助我们防止一段程序阻塞应用程序的事件队列.使用下面代码,可以很容易使一个应用程序陷入泥潭. while(true){} 而且它并不需要一个无限循环来写一个缓慢的程序.代码 ...

  3. @synthesize vs. @dynamic

    @synthesize will generate getter and setter methods and corresponding instance variable for your pro ...

  4. HttpContext.Current.Cache使用文件依赖问题

    HttpContext.Current.Cache.Insert("FCacheMs", tb, New CacheDependency(HttpContext.Current.S ...

  5. cargo failed to finish deploying within the timeout period [120000]

    cargo插件,报错:failed to finish deploying within the timeout period [120000] 解决方法:配置timeout为0 <plugin ...

  6. GAT2.0使用文档(组合接口测试)

    3.2接口用例场景组件 在此之前,大家应该都已经开发完成了一个最简单的接口测试用例,但是之前的接口用例的期望结果是固定值,不能动态的去做对比,有很大局限性.下面开始介绍怎样通过场景组件来动态对测试结果 ...

  7. mysql 允许远程登陆

    参考:http://blog.chinaunix.net/uid-23215128-id-2951624.html 1.以root账户登录 2.grant all PRIVILEGES on disc ...

  8. ALLOCATE语句分配FORTRAN动态数组方法(转自http://blog.csdn.net/zhuxianjianqi/article/details/8067174)

    数组的动态分配 a)    可分配数组 数组可以是静态的也可以是动态的.如果数组是静态的,则在编译时就被分配了固定的储存空间,并且直到程序退出时才被释放.程序运行时静态数组的大小不能改变.静态数组的缺 ...

  9. java开发环境的主题色的变化

     eclipse:Help->Install New Software->Work with:Update Site - http://eclipse-color-theme.github ...

  10. UDP:用户数据报协议

    UDP是一个简单的面向数据报的运输层协议:进程的每个输出操作都正好产生一个UDP数据报,并组装成一份待发送的IP数据报.这与面向流字符的协议不同,如TCP,应用程序产生的全体数据与真正发送的单个IP数 ...