QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#574937 | #1465. Not Our Problem | oceeff | RE | 126ms | 6020kb | C++14 | 2.9kb | 2024-09-19 09:04:04 | 2024-09-19 09:04:04 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
#endif
#define int long long
using namespace std;typedef __int128 lll;int read(){int num=0,f=1;char c;while(!isdigit(c=getchar()))if(c=='-')f=-1;while(isdigit(c))num=num*10+(c&15),c=getchar();return num*f;}void write(int x,char ch=' '){int F[20],cnt=0;if(!x)putchar('0');if(x<0)putchar('-'),x=-x;while(x)F[cnt++]=x%10+'0',x/=10;while(cnt)putchar(F[--cnt]);putchar(ch);}
namespace Main
{
/*
F(i)=(i>B?sqrt(k/i):k/(i*i))
min<=B
F(a,b)=F(a,a)+F([1,a],[a+1,b])=\sum_{i=a+1}^b min(a,sqrt(k/i)) r=k/(v*v)-1 sqrt(k/j)<min(a,sqrt(k/i))
sqrt(k/j)<v k/j<v*v j>k/(v*v)
F(a,a):2*G(a,b) a<=b -min(a,B)
\sum_{i=1}^a min(k/(i*i),a)-i+1
v=k/(i*i) k/(j*j)<v j>sqrt(k/v)
*/
const int N=1000010,mod=998244353,inf=1e18;void Add(int&x,int y){(x+=y)>=mod&&(x-=mod);}int n,m,k,ans,a[N],x,y,z,xx,yy,zz;int sq(int x){return (int)sqrt(1.*x);}int F(int i){return i?(k?(i>m?sq(k/i):k/(i*i)):0):inf;}int S(int x){return (lll)x*(x+1)/2%mod;}
int G(int x,int y){int res=0;for(int i=x+1,j,z;i<=y;i=j+1)z=min(x,sq(k/i)),j=min(y,k/(z*z)),res=(res+(lll)(j-i+1)*z)%mod;/*printf("G %lld %lld %lld\n",x,y,res);*/return res;}
int F(int x,int y){if(x>y)swap(x,y);int res=0,r=min(x,m);/*for(int i=1;i<=r;++i)res=(res+min(x,k/(i*i))-i+1)%mod;*/for(int i=1,j,z;i<=r;i=j+1)z=min(x,k/(i*i)),j=min(r,sq(k/z)),/*assert(j>=i),*/res=(res+(lll)(j-i+1)*z)%mod;res=(res+r-S(r)+mod)%mod,res=(res*2+G(x,y)-r+x+y+1+mod)%mod;
/*int s=0;for(int i=0;i<=x;++i)for(int j=0;j<=y;++j)s+=(min(i,j)*i*j<=k);printf("F %lld %lld %lld %lld\n",x,y,res,s);assert(res==s);*/return res;}
void main()
{
n=read(),k=read(),ans=1;for(int i=1;i<=n;++i)a[i]=read();/*if((n==1&&a[1]==-1)||(a[1]==-1&&a[2]==-1)||(a[n-1]==-1&&a[n]==-1))return write(-1,'\n');for(int i=1;i<=n-2;++i)if(a[i]==-1&&a[i+1]==-1&&a[i+2]==-1)return write(-1,'\n');*/for(int i=1;i<n;++i)if(a[i]>0&&a[i+1]>0&&min(a[i],a[i+1])>k/a[i]/a[i+1])return write(0,'\n');
for(int i=1,j;i<=n;)if(a[i]!=-1)++i;else{for(j=i;j<n&&a[j+1]==-1;++j);if((j-i+1)+(!a[i-1])+(!a[j+1])>=3)return write(-1,'\n');i=j+1;}if(!k)return write(1,'\n');m=(k?(int)cbrt(1.*k):0);for(;(m+1)*(m+1)*(m+1)<=k;++m);for(;m*m*m>k;--m);
for(int i=1,j;i<=n;)if(a[i]!=-1)++i;else{for(j=i;j<n&&a[j+1]==-1;++j);if(i==j)ans=(lll)ans*(F(max(a[i-1],a[i+1]))+1)%mod;else ans=(lll)ans*F(F(a[i-1]),F(a[j+1]))%mod;i=j+1;}write(ans,'\n');
// for(int i=1;i<=100;++i)for(int j=1;j<=100;++j)F(i,j);
}
}
signed main()
{
// freopen("ex_seq.in","r",stdin);
// freopen("ex_seq1.in","r",stdin),freopen(".out","w",stdout);
const bool base=0,IO=1;int T;if(!base)T=1;else if(IO)T=read();else ios::sync_with_stdio(0),cin>>T;for(;T--;)Main::main();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5796kb
input:
4 100 -1 7 2 -1
output:
104
result:
ok 1 number(s): "104"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5884kb
input:
4 100 10 -1 -1 1
output:
240
result:
ok 1 number(s): "240"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5756kb
input:
1 0 -1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5892kb
input:
2 10 10 10
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5944kb
input:
7 1000 -1 25 0 388 -1 -1 1
output:
14014
result:
ok 1 number(s): "14014"
Test #6:
score: 0
Accepted
time: 1ms
memory: 6020kb
input:
10 1000000 -1 71350 0 6 -1 2 2 -1 -1 358968
output:
652782809
result:
ok 1 number(s): "652782809"
Test #7:
score: 0
Accepted
time: 22ms
memory: 5884kb
input:
7 1000000000000000000 -1 193562447565998153 0 10833 -1 -1 12700
output:
429385005
result:
ok 1 number(s): "429385005"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5732kb
input:
100 1000 -1 174 2 -1 -1 1 2 -1 -1 2 139 -1 -1 1 4 -1 -1 1 1 -1 -1 4 18 -1 -1 356 1 -1 -1 31 1 -1 -1 1 2 -1 -1 1 7 -1 -1 2 0 509 -1 -1 174 0 22 -1 -1 1 1 -1 -1 801 0 2 -1 -1 6 2 -1 -1 1 23 -1 -1 446 0 927 -1 -1 635 1 -1 -1 513 0 5 -1 -1 2 6 -1 -1 2 1 -1 -1 839 0 342 -1 -1 8 1 -1 -1 2
output:
240069117
result:
ok 1 number(s): "240069117"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5808kb
input:
100 1000000 2 -1 -1 257208 1 -1 -1 80 14 -1 -1 20 113 -1 -1 2 155991 -1 -1 1 805463 -1 -1 734 1 -1 -1 942182 0 3 -1 -1 1 1 -1 -1 3 88674 -1 -1 718 0 793 -1 -1 540 1 -1 -1 1 893042 -1 -1 891 0 491 -1 -1 6 18 -1 -1 1 735332 -1 -1 1 1 -1 -1 231702 0 22 -1 -1 1 476 -1 -1 826 20 -1 -1 1 29 -1 -1 2 989 -1...
output:
279593366
result:
ok 1 number(s): "279593366"
Test #10:
score: 0
Accepted
time: 126ms
memory: 5928kb
input:
97 1000000000000000000 -1 55 1 -1 -1 844479880 0 123881535849416001 -1 -1 128083297778537531 1 -1 -1 171572811 0 352900396625380054 -1 -1 1 1 -1 -1 41 6 -1 -1 21627 155 -1 643122694 0 392322295 -1 -1 254987357 2 -1 -1 4 0 571457328786259212 -1 -1 1 8816 -1 -1 131254846109630352 0 971779784498766346 ...
output:
188490398
result:
ok 1 number(s): "188490398"
Test #11:
score: -100
Runtime Error
input:
999998 1000 -1 343 1 -1 -1 1 3 -1 -1 1 1 -1 -1 2 0 468 -1 -1 1 1 -1 -1 783 0 5 -1 -1 2 0 760 -1 -1 318 1 -1 -1 1 320 -1 -1 27 1 -1 -1 2 2 -1 -1 2 1 -1 -1 997 1 -1 -1 547 0 313 -1 -1 4 0 304 -1 -1 1 4 -1 -1 980 0 96 -1 -1 1 797 -1 -1 13 0 13 -1 -1 19 0 401 -1 -1 1 1 -1 -1 5 5 -1 -1 26 0 458 -1 -1 6 0...