QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#442950#8527. Power Divisionsucup-team1004#WA 0ms25936kbC++141.7kb2024-06-15 13:54:462024-06-15 13:54:46

Judging History

你现在查看的是最新测评结果

  • [2024-06-15 13:54:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:25936kb
  • [2024-06-15 13:54:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod=1e9+7,N=3e5+10,M=2e6;
const ll P=7881299347898369ll;
int n,a[N],f[N],t[N],len,ls[N],rs[N];
unordered_map<ll,int> t1,t2;
ll Mod(ll a){return a<P?a:a-P;}
ld s[N];
ll b[N],pw[M+10];
void pls(int &a,int b)
{
	if((a+=b)>=mod) a-=mod;
}
void update(int x)
{
	pls(f[x],t1[b[x]]);
	pls(t2[b[x]],f[x]);
}
void solve(int l,int r,int now)
{
	int s1=now-1-l,s2=r-now,cur=ceil(log(s[now])/log(2))+2;
	if(s1>=s2)
	{
		for(int k=0;k<=cur;k++)
			for(int i=now;i<=r;i++)
				pls(f[i],mod-t2[Mod(b[i]-pw[k+a[now]]+P)]);
	}
	if(ls[now]) solve(l,now-1,ls[now]);
	else update(l);
	if(s1<s2)
	{
		for(int k=0;k<=cur;k++)
			for(int i=l;i<now;i++)
				pls(t1[Mod(b[i]+pw[k+a[now]])],f[i]);
	}
	else
	{
		for(int k=0;k<=cur;k++)
			for(int i=now;i<=r;i++)
				pls(f[i],t2[Mod(b[i]-pw[k+a[now]]+P)]);
	}
	if(rs[now]) solve(now,r,rs[now]);
	else update(r);
	if(s1<s2)
	{
		for(int k=0;k<=cur;k++)
			for(int i=l;i<now;i++)
				pls(t[Mod(b[i]+pw[k+a[now]])],mod-f[i]);
	}
}
ld calc(int k,ld s)
{
	for(int i=0;i<k&&s>1e-6;i++) s*=0.5;
	return s;
}
void dfs(int x)
{
	s[x]=1;
	if(ls[x])
	{
		dfs(ls[x]);
		s[x]+=calc(a[x]-a[ls[x]],s[ls[x]]);
	}
	if(rs[x])
	{
		dfs(rs[x]);
		s[x]+=calc(a[x]-a[rs[x]],s[rs[x]]);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=pw[0]=1;i<=M;i++) pw[i]=pw[i-1]*2%P;
	for(int i=1;i<=n;i++) b[i]=(b[i-1]+pw[a[i]])%P;
	for(int i=1;i<=n;i++)
	{
		while(len&&a[t[len]]<a[i]) ls[i]=t[len--];
		if(len) rs[t[len]]=i;
		t[++len]=i;
	}
	f[0]=1;
	dfs(t[1]);
	solve(0,n,t[1]);
	printf("%d\n",f[n]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 25936kb

input:

5
2 0 0 1 1

output:

7

result:

wrong answer 1st numbers differ - expected: '6', found: '7'