#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5;
int n, k, q, a[maxn+5], pref[maxn+5], pos[15], pre[maxn+5], suf[maxn+5];
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k;
for (int i=1; i<=n; i++) {
cin >> a[i];
}
pref[0] = pre[0] = suf[n+1] = 0;
for (int i=1; i<=n; i++) {
pref[i] = pref[i-1] + a[i];
pre[i] = pre[i-1] + a[i] * i;
suf[n-i+1] = suf[n-i+2] + a[n-i+1] * i;
}
cin >> q;
while (q--) {
int t;
cin >> t;
if (t == 1) {
for (int i=1; i<=k; i++) {
cin >> pos[i];
}
continue; // subtask 1, 2
}
else {
int l, r, m;
cin >> l >> r >> m;
int len = r - l + 1;
int h = min(len/2, m);
int x = l + h - 1, y = r - h + 1;
int ans = (h*(pref[y] - pref[x-1])) + (pre[x-1]-pre[l-1]-(l-1)*(pref[x-1]-pref[l-1])) + (suf[y+1]-suf[r+1]-(n-r)*(pref[r]-pref[y]));
// cout << "len: " << len << " x: " << x << " y: " << y << " h: " << h << "\n";
cout << ans << "\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
4432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |