HDU 4913(Least common multiple-线段树+容斥)
来源:互联网 发布:手机期货模拟软件 编辑:程序博客网 时间:2024/06/10 00:06
Least common multiple
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 767 Accepted Submission(s): 257
Problem Description
bobo has an integer set S={x1,x2,…,xn}, where xi=2ai * 3bi.
For each non-empty subsets of S, bobo added the LCM (least common multiple) of the subset up. Find the sum of LCM modulo (109+7).
For each non-empty subsets of S, bobo added the LCM (least common multiple) of the subset up. Find the sum of LCM modulo (109+7).
Input
The input consists of several tests. For each tests:
The first line contains n (1≤n≤105). Each of the following n lines contain 2 integers ai,bi (0≤ai,bi≤109).
The first line contains n (1≤n≤105). Each of the following n lines contain 2 integers ai,bi (0≤ai,bi≤109).
Output
For each tests:
A single integer, the value of the sum.
A single integer, the value of the sum.
Sample Input
20 11 031 22 11 2
Sample Output
11174
Author
Xiaoxu Guo (ftiasch)
Source
2014 Multi-University Training Contest 5
Recommend
We have carefully selected several similar problems for you: 5426 5425 5424 5423 5422
按Ai从小到大,Bi从小到大加入,考虑加入的数对答案的影响
b<Bi有cnt个 故
#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<functional>#include<iostream>#include<cmath>#include<cctype>#include<ctime>#include<vector>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (o<<1)#define Rson ((o<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define MEM2(a,i) memset(a,i,sizeof(a));#define INF (2139062143)#define F (1000000007)#define MAXN (100000+10)#define fi first#define se second#define mp make_pairtypedef __int64 ll;ll mul(ll a,ll b){return (a%F*b%F)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}ll pow2(ll a,ll b){if (b==0) return 1;if (b==1) return a;ll p = pow2(a,b/2);p=p*p%F;if ( b & 1 ) p = p * a%F;return p;} class SegmentTree { ll a[MAXN*4],sumv[MAXN*4],a2[MAXN*4],sumv2[MAXN*4]; int mark[MAXN*4]; int n; public: SegmentTree(){MEM(a) MEM(sumv) MEM(a2) MEM(sumv2) MEM(mark) } SegmentTree(int _n):n(_n){MEM(a) MEM(sumv) MEM(a2) MEM(sumv2) MEM(mark) } void mem(int _n) { n=_n; MEM(a) MEM(sumv) MEM(a2) MEM(sumv2) MEM(mark) } void maintain(int o,int L,int R) { if (L<R) {sumv[o]=(sumv[Lson]+sumv[Rson])%F;sumv2[o]=(sumv2[Lson]+sumv2[Rson])%F;} }int y1,y2;ll v;void update(int o,int L,int R) //y1,y2,v{if (L==R) {sumv[o]++; sumv2[o]=(sumv2[o]+v)%F;return ;}else{pushdown(o);int M=(R+L)>>1;if (y1<=M) update(Lson,L,M); else update(Rson,M+1,R); }maintain(o,L,R); }void update2(int o,int L,int R) {if (y1<=L&&R<=y2) {mark[o]++;sumv2[o]=(2*sumv2[o])%F;return;}else{pushdown(o);int M=(R+L)>>1;if (y1<=M) update2(Lson,L,M); if (M< y2) update2(Rson,M+1,R); }maintain(o,L,R); }void pushdown(int o) { if (mark[o]){ mark[Lson]+=mark[o];mark[Rson]+=mark[o];ll t=pow2(2,mark[o]);sumv2[Lson]=sumv2[Lson]*t%F;sumv2[Rson]=sumv2[Rson]*t%F;mark[o]=0;}}ll _sum,_sum2; void query2(int o,int L,int R){if (y1<=L&&R<=y2){upd(_sum,sumv[o]);upd(_sum2,sumv2[o]);return;} else {pushdown(o);int M=(L+R)>>1;if (y1<=M) query2(Lson,L,M);if (M< y2) query2(Rson,M+1,R);}}void add(int l,ll v){y1=y2=l;this->v=v;update(1,1,n);}void mul(int l,int r){if (l>r) return ; y1=l,y2=r;update2(1,1,n);}ll ask(int l,int r,int b=1){if (l>r) return 0; _sum=_sum2=0;y1=l,y2=r;query2(1,1,n);if (b==1) return _sum;return _sum2;}void print(){For(i,n)cout<<ask(i,i,2)<<' ';cout<<endl;}}S; int n;pair<ll,ll> p[MAXN];ll bb[MAXN];int main(){//freopen("hdu4913.in","r",stdin);//freopen(".out","w",stdout);while(scanf("%d",&n)==1) {int a,b;For(i,n) scanf("%d%d",&a,&b),p[i]=mp(a,b),bb[i]=p[i].se;sort(p+1,p+1+n);sort(bb+1,bb+1+n);int m=unique(bb+1,bb+1+n)-(bb+1);S.mem(m); ll ans = 0;For(i,n) {ll a=p[i].fi,b=p[i].se;ll now=pow2(2LL,a),now3=pow2(3LL,b);ll nowv=mul(now,now3);int pos = lower_bound( bb+1 , bb+1+m , p[i].se ) - (bb);ll cnt=S.ask( 1,pos,1);ll tmp=pow2(2,cnt);upd( ans , nowv * tmp % F );upd( ans , now * S.ask(pos+1,m,2) % F);S.mul(pos+1,m);S.add(pos,mul(now3,tmp));} printf("%I64d\n",ans%F); }return 0;}
0 0
- HDU 4913(Least common multiple-线段树+容斥)
- 【HDU 4913】Least common multiple【线段树】
- hdu 4913 Least common multiple 线段树
- hdu 4913 Least common multiple(线段树)
- HDU 4913 Least common multiple 线段树
- HDU 4913 Least common multiple 解题报告(线段树)
- HDU 4913 Least common multiple
- [HDOJ 4913] Least common multiple [动态规划+线段树]
- hdu Least Common Multiple
- HDU Least Common Multiple
- HDU 1019 Least Common Multiple
- hdu 1019 Least Common Multiple
- HDU-1019 least common multiple
- HDU 1019 Least Common Multiple
- HDU 1019 Least Common Multiple
- HDU 1019 Least Common Multiple
- HDU 1019 Least Common Multiple
- hdu 1019Least Common Multiple
- 存在必有其合理性
- C++_typeid用法
- hdu1240
- 发烧[疾病] - 一些益处
- Chart 控件 for vs2008的安装
- HDU 4913(Least common multiple-线段树+容斥)
- UCOSII移植笔记(UCOSII+STM32F103+LED)
- 2015年9月5 进驻csdn
- 快速安装mysql tcl expect
- unity编辑器设备丢失
- 左递归文法
- linux命令之grep
- 总而言之 32 屌丝男不会拒绝别人
- Objective-C 对象特性