QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#820062#1465. Not Our ProblemcwfxlhWA 4ms20844kbC++141.7kb2024-12-18 19:19:372024-12-18 19:19:37

Judging History

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

  • [2024-12-18 19:19:37]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:20844kb
  • [2024-12-18 19:19:37]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define MOD 998244353
using namespace std;
int n,c,a[1000003],f[1000003],pre[1000003],ans=1,lmt[1000003],gg;
bool chk(int X,int Y){
	if(X>Y)swap(X,Y);
	if(X>1000000)return false;
	if(X==0||Y==0)return true;
	if((c/(X*X))<Y)return false;
	return true;
}
int calc(int X){
	if(X==0)return c;
	if(chk(X,X))return f[X];
	return (int)(sqrt(c/X));
}
int getsum(int l,int r){return ((r-l+1)%MOD)*(((l+r)%MOD)*((MOD+1)/2)%MOD)%MOD;}
int lft,rgt,mid;
int getnum(int X,int Y){
	X=min(X,Y);
	X=min(X,gg);
	int ret=0;
	lft=0;
	rgt=X;
	while(lft<rgt){
		mid=((lft+rgt)>>1)+1;
		if(f[mid]>=Y)lft=mid;
		else rgt=mid=1;
	}
	ret=((Y%MOD)*((lft+1)%MOD)-getsum(-1,lft-1))%MOD;
	ret=(ret+pre[X]-pre[lft])%MOD;
	return ret;
}
signed main(){
	ios::sync_with_stdio(false);
	cin>>n>>c;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++){
		if(a[i]==-1&&((i==1)||(a[i-1]==0)||(a[i-1]==-1))&&((i==n)||(a[i+1]==0)||(a[i+1]==-1))){
			cout<<-1;
			return 0;
		}
	}
	for(int i=1;i<=1000000;i++){
		if(i*i*i>c)f[i]=i-1;
		else f[i]=(c/(i*i));
		if(i*i*i<=c)gg=i;
		pre[i]=(pre[i-1]+f[i]-i+1)%MOD;
	}
	f[0]=c;
	for(int i=1;i<=n;i++)lmt[i]=c;
	for(int i=1;i<n;i++){
		if(a[i]!=-1&&a[i+1]!=-1&&(!chk(a[i],a[i+1]))){
			cout<<0;
			return 0;
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]!=-1){
			if(i>1)lmt[i-1]=min(lmt[i-1],calc(a[i]));
			if(i<n)lmt[i+1]=min(lmt[i+1],calc(a[i]));
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]!=-1)continue;
		if(i==n||a[i+1]!=-1){
			ans=ans*((lmt[i]+1)%MOD)%MOD;
			continue;
		}
		ans=ans*((getnum(lmt[i],lmt[i+1])+getnum(lmt[i+1],lmt[i])-min(lmt[i],gg)-1)%MOD)%MOD;
		i++;
	}
	ans%=MOD;
	ans+=MOD;
	ans%=MOD;
	cout<<ans;
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 19548kb

input:

4 100
-1 7 2 -1

output:

104

result:

ok 1 number(s): "104"

Test #2:

score: 0
Accepted
time: 4ms
memory: 20844kb

input:

4 100
10 -1 -1 1

output:

240

result:

ok 1 number(s): "240"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5652kb

input:

1 0
-1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

2 10
10 10

output:

0

result:

ok 1 number(s): "0"

Test #5:

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

input:

7 1000
-1 25 0 388 -1 -1 1

output:

14014

result:

ok 1 number(s): "14014"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 20800kb

input:

10 1000000
-1 71350 0 6 -1 2 2 -1 -1 358968

output:

641782721

result:

wrong answer 1st numbers differ - expected: '652782809', found: '641782721'