제출 #777640

#제출 시각아이디문제언어결과실행 시간메모리
777640ihcekerAddk (eJOI21_addk)C++14
92 / 100
203 ms7120 KiB
#include<bits/stdc++.h> #define int long long #define MOD 1000000007 #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; int32_t main(){ int n,k; cin>>n>>k; int arr[n+5],pre[n+5],pre2[n+5],suf[n+5]; pre[0]=0; pre2[0]=0; suf[n+1]=0; for(int i=1;i<=n;i++){ cin>>arr[i]; pre[i]=pre[i-1]+arr[i]; pre2[i]=pre2[i-1]+arr[i]*i; } for(int i=n;i>=1;i--){ suf[i]=suf[i+1]+arr[i]*(n-i+1); } int q; cin>>q; while(q--){ int a; cin>>a; if(a==1){ int b[k]; for(int i=0;i<k;i++)cin>>b[i]; } else{ int x,y,z; cin>>x>>y>>z; if(z==1){ cout<<pre[y]-pre[x-1]<<endl; continue; } int l=x+z-1,r=y-z+1; cout<<(pre[r]-pre[l-1])*z+pre2[l-1]-pre2[x-1]-(pre[l-1]-pre[x-1])*(x-1)+suf[r+1]-suf[y+1]-(pre[y]-pre[r])*(n-y)<<endl; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...