#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 11;
const int inf = 1e18;
int a[N], s[N], rs[N], p[N];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n, k, q;
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i];
p[i] = a[i] + p[i - 1];
s[i] = s[i - 1] + a[i] * i;
rs[i] = rs[i - 1] + a[i] * (n - i + 1);
}
cin >> q;
while(q--){
int t;
cin >> t;
if(t == 1){
int x;
cin >> x;
}
else{
int l, r, m;
cin >> l >> r >> m;
int len = (r - l + 1);
int ans = (p[r - len + m] - p[l + len - m - 1]) * min(len - m + 1, m);
int L = l, R = l + (len - m) - 1;
if(L <= R) ans += s[R] - s[L - 1] - (p[R] - p[L - 1]) * (L - 1);
R = r, L = r - (len - m) + 1;
if(L <= R) ans += rs[R] - rs[L - 1] - (p[R] - p[L - 1]) * (n - R);
cout << ans << '\n';
}
}
}
// hello karim nurbakyt sanzhar azamat congratulation europa asia america laplas
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |