Submission #476195

#TimeUsernameProblemLanguageResultExecution timeMemory
476195dzdzxAddk (eJOI21_addk)C++17
0 / 100
151 ms2040 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n,k; cin>>n>>k; int x[n]; for (int i=0;i<n;i++){ cin>>x[i]; } long long f1[n]; long long f2[n]; long long f3[n]; f1[0]=x[0]; f2[0]=x[0]; for (int i=1;i<n;i++){ f1[i]=f1[i-1]+x[i]; f2[i]=f2[i-1]+(i+1)*x[i]; } f3[n-1]=x[n-1]; for (int i=n-2;i>=0;i--){ f3[i]=f3[i+1]+(n-i)*x[i]; } int q; cin>>q; for (int i=0;i<q;i++){ int u; cin>>u; if (u==2){ int a,b,m; cin>>a>>b>>m;a--;b--; if (b-a+1>=(m-1)*2){ int sum=0; int s1=0; int s2=0; int s3=0; s1=f2[m+a-2]-f2[a-1]; s1-=a*(f1[m+a-2]-f1[a-1]); s2=m*(f1[b-m+1]-f1[m+a-2]); s3=f3[b-m+2]-f3[b+1]; s3-=(n-b-1)*(f1[b]-f1[b-m+1]); cout<<s1+s2+s3<<endl;; }else{ int sum=0; int s1=0; int s2=0; int s3=0; int num=(b-a+1)-m; s1=f2[b-m]-f2[a-1]; s1-=a*(f1[b-m]-f1[a-1]); s2=(num+1)*(f1[a+m-1]-f1[b-m]); s3=f3[a+m]-f3[b+1]; s3-=(n-b-1)*(f1[b]-f1[a+m-1]); cout<<s1+s2+s3<<endl;; } }else{ for (int j=0;j<k;j++){ int z; cin>>z; } } } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:34:9: warning: unused variable 'sum' [-Wunused-variable]
   34 |     int sum=0;
      |         ^~~
Main.cpp:45:9: warning: unused variable 'sum' [-Wunused-variable]
   45 |     int sum=0;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...