Submission #978373

#TimeUsernameProblemLanguageResultExecution timeMemory
978373sleepntsheepFish 3 (JOI24_fish3)C++17
9 / 100
2069 ms12896 KiB
long long lo(long long a,long long b){return a<b?a:b;} long long hi(long long a,long long b){return a>b?a:b;} #include<stdio.h> #include<assert.h> #include<string.h> #define N 300005 int n,q; long long d,c[N],t[N],b[N],pc[N],bo,suff_min[N]; int main() { scanf("%d%lld",&n,&d); for(int i=1;i<=n;++i) { scanf("%lld",c+i),pc[i]=pc[i-1]+c[i]; if(!c[i])b[bo++]=i; } scanf("%d",&q); for(int l,r,i=0;i<q;++i) { scanf("%d%d",&l,&r); memcpy(t,c,sizeof t); long long run=0,z=0; for(int i=l;i<=r;++i) { if(t[i]<run) { puts("-1"); goto X; } run+=(t[i]-run)%d; t[i]-=run; } suff_min[r]=t[r]; for(int i=r-1;i>=l;--i)suff_min[i]=lo(suff_min[i+1],t[i]); run=0; for(int i=l;i<=r;++i) { if(suff_min[i]-run>=d) { for(int j=i;j<=r;++j) t[i]-=(suff_min[i]-run)/d*d; run+=(suff_min[i]-run)/d*d; } } for(int i=l;i<=r;++i) { if(t[i]%d){puts("-1");goto X;} z+=t[i]/d; } printf("%lld\n",z); X:; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d%lld",&n,&d);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%lld",c+i),pc[i]=pc[i-1]+c[i];
      |         ~~~~~^~~~~~~~~~~~
Main.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
Main.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf("%d%d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...