QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#442939#8527. Power Divisionsucup-team1004#WA 12ms27704kbC++141.7kb2024-06-15 13:53:022024-06-15 13:53:02

Judging History

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

  • [2024-06-15 13:53:02]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:27704kb
  • [2024-06-15 13:53:02]
  • 提交

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: 100
Accepted
time: 7ms
memory: 26856kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 10ms
memory: 24500kb

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 3ms
memory: 27704kb

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 7ms
memory: 25912kb

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 3ms
memory: 26848kb

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 12ms
memory: 25988kb

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 11ms
memory: 27036kb

input:

7
3 4 3 5 6 3 4

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 3ms
memory: 25728kb

input:

10
8 6 5 6 7 8 6 8 9 9

output:

4

result:

ok 1 number(s): "4"

Test #9:

score: -100
Wrong Answer
time: 5ms
memory: 26996kb

input:

96
5 1 0 2 5 5 2 4 2 4 4 2 3 4 0 2 1 4 3 1 2 0 2 2 3 2 4 5 3 5 2 0 2 2 5 3 0 4 5 3 5 4 4 3 1 2 0 5 4 5 0 2 3 2 4 0 0 4 2 0 2 5 3 3 1 5 5 1 1 1 0 5 0 3 0 2 1 1 0 5 0 3 3 4 4 5 3 0 2 2 0 5 4 5 0 5

output:

12787944

result:

wrong answer 1st numbers differ - expected: '11332014', found: '12787944'