Submission #1030918

#TimeUsernameProblemLanguageResultExecution timeMemory
1030918sleepntsheepAddk (eJOI21_addk)C11
92 / 100
40 ms6228 KiB
#include<stdio.h> #define N 100000 #define N_ N+1 int lo(int i,int j){return i<j?i:j;} int hi(int i,int j){return -lo(-i,-j);} int n,k,q_,a[N_],a_,x,y,m; long long p[N_],q[N_],s[N_+1]; long long lt(int l,int r){ return r<l?0:(p[r]-p[l-1])*(n-l+1+1ll)-(s[l]-s[r+1]); } long long rt(int l,int r){ return r<l?0:(p[r]-p[l-1])*(r+1ll)-(q[r]-q[l-1]); } int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=n;++i)scanf("%d",a+i),p[i]=p[i-1]+a[i],q[i]=q[i-1]+1ll*i*a[i]; for(int i=n;i>=1;--i)s[i]=s[i+1]+1ll*(n-i+1)*a[i]; scanf("%d",&q_); for(;q_--;){ scanf("%d",&a_); if(a_==1)scanf("%*d"); else{ scanf("%d%d%d",&x,&y,&m); if(x+m-1>y){puts("0");continue;} int nrange=y-x+1-m+1; int pk=lo(nrange,m),p1=x+pk-1,p2=y-pk+1; //printf(" [%d %d] - range = %d, peak = %d, p1 = %d, p2 = %d\n",x,y,nrange,pk,p1,p2); printf("%lld\n",(p[p2]-p[p1-1])*1ll*pk+lt(x,p1-1)+rt(p2+1,y)); } } } /* * queries * * when ask [l, r, m] * if r - l + 1 < m - zero * else * [1, 1, 1, 1, 1] * [1, 2, 2, 2, 2, 1] * [1, 2, 3, 3, 3, 2, 1] * * */

Compilation message (stderr)

Main.c: In function 'main':
Main.c:16:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d%d",&n,&k);
      |     ^~~~~~~~~~~~~~~~~~~
Main.c:17:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     for(int i=1;i<=n;++i)scanf("%d",a+i),p[i]=p[i-1]+a[i],q[i]=q[i-1]+1ll*i*a[i];
      |                          ^~~~~~~~~~~~~~~
Main.c:19:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d",&q_);
      |     ^~~~~~~~~~~~~~~
Main.c:21:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d",&a_);
      |         ^~~~~~~~~~~~~~~
Main.c:22:18: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         if(a_==1)scanf("%*d");
      |                  ^~~~~~~~~~~~
Main.c:24:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |             scanf("%d%d%d",&x,&y,&m);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...