tj:題解裡公式是錯的

我們可以考慮每一個節點[a,a+2^b-1]對答案的貢獻

則當這個節點是左兒子時,貢獻為2^b

是右兒子時,貢獻為2n−a−2b+12^n-a-2^b+12n−a−2b+1

左兒子的公式為2^(n-2)n(n+1)

右兒子需要通過等比數列化簡。為(2(n−1)+1)∗((n−1)∗2n+1)−2(n−2)∗n∗(n+1)(2^(n-1)+1)*((n-1)*2^n+1)-2^(n-2)*n*(n+1)(2(n−1)+1)∗((n−1)∗2n+1)−2(n−2)∗n∗(n+1)

然後由於每一個節點作為左端點和右端點貢獻相等,所以要乘2

最終答案為((2(n−1)+1)∗((n−1)∗2n+1))/(2(n−1)∗(2n+1))((2^(n-1)+1)*((n-1)*2^n+1))/(2^(n-1)*(2^n+1))((2(n−1)+1)∗((n−1)∗2n+1))/(2(n−1)∗(2n+1))

代碼:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mo 1000000007ll
ll n;
ll qp(ll x,ll y){
	if(!y)return 1;
	if(y==1)return x%mo;
	ll r=qp(x,y/2);
	if(y&1)return r*r%mo*x%mo;
	return r*r%mo;
}
int main(){
	freopen("A.in","r",stdin);
	freopen("A.out","w",stdout);
	scanf("%lld",&n);
	ll ans1=qp(2ll,n-1ll);
	ans1=(ans1+1ll)%mo;
	ll ans2=(n-1ll+mo)%mo;
	ans2=(ans2*qp(2ll,n))%mo;
	ans2=(ans2+1ll)%mo;
	ll ans3=ans1*ans2%mo;
	ll ans4=qp(2ll,n-2ll);
	ans4=ans4*(qp(2ll,n)+1ll)%mo;
	ll ans5=qp(ans4,mo-2ll);
	printf("%lld\n",ans3*ans5%mo);
}

jzoj5928的更多相关文章

随机推荐

  1. Connecting to MQSeries with .NET

    By connecting to MQSeries withing a .NET application, first it has to be done is to install MQ Serie ...

  2. [Git]Git的常用命令

    Update: git status git diff wq git commit -am "why update files" git push Add: git add . g ...

  3. hadoop 学习(四)之java操作hdfs

    1.导入hadoop jar包 将hadoop/share/common/目录.hadoop/share/common/lib/目录.hadoop/hdfs/目录.下的jar包加入eclipse. 2 ...

  4. 共享内存system v(未编译)

    #include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> ...

  5. 2018.07.06 POJ1556 The Doors(最短路)

    The Doors Time Limit: 1000MS Memory Limit: 10000K Description You are to find the length of the shor ...

  6. 搭建Idea授权服务器用于学习

    我自己的搭建服务器http://doit.wenyule.top 懒得看教程或弄不好的小伙伴可以用我搭建的,在激活那选择服务器,输入我上面的地址,注意可以激活2018.2.1之前的.为了防止用的人太多 ...

  7. 山东省第七届ACM竞赛 J题 Execution of Paladin (题意啊)

    题意:鱼人是炉石里的一支强大种族,在探险者协会里,圣骑士有了一张新牌,叫亡者归来,效果是召唤本轮游戏中7个已死鱼人.如果死掉的不足7个,那么召唤的数量就会不足7. 鱼人有很多,下面的4个是: 寒光智者 ...

  8. generate

    一:generate Verilog-2001添加了generate循环,允许产生module和primitive的多个实例化,同时也可以产生多个variable,net,task,function, ...

  9. Spring源码解析 - AbstractBeanFactory 实现接口与父类分析

    我们先来看类图吧: 除了BeanFactory这一支的接口,AbstractBeanFactory主要实现了AliasRegistry和SingletonBeanRegistry接口. 这边主要提供了 ...

  10. x11vnc配置--ubuntu14.04

    x11vnc是连接到真实的X会话,相比vnc4server和tightvncserver自己创建不同分辨率的xserver来说,画面延时和显示效果应该要好一些.两种服务都试过,个人感觉x11vnc要好 ...