#include "bits/stdc++.h"
#define int long long
using namespace std;
const int sz = 1e5 + 5;
int pf[sz], sf[sz];
int pj[sz], sj[sz];
int a[sz];
int an;
void solve() {
int t;
cin >> t;
if (1 == t) {
int b;
cin >> b;
return;
}
int l, r, m;
cin >> l >> r >> m;
int n = r - l + 1;
int mxv = n - m + 1;
int le = l + mxv - 2;
int rs = r - mxv + 2;
int pjl = pj[le] - pj[l - 1];
int pfl = pf[le] - pf[l - 1];
int fpl = pjl - pfl * (l - 1);
int sjr = sj[rs] - sj[r + 1];
int sfr = sf[rs] - sf[r + 1];
int fsr = sjr - sfr * (an - r);
int rsms = l + mxv - 1;
int rsme = r - mxv + 1;
int rsm = pf[rsme] - pf[rsms - 1];
int tsm = fpl + fsr + rsm * mxv;
cout << tsm << '\n';
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, k;
cin >> n >> k;
an = n;
for (int i = 1; i <= n; i ++)
cin >> a[i];
for (int i = 1; i <= n; i ++) {
pf[i] = pf[i - 1] + a[i];
pj[i] = pj[i - 1] + i * a[i];
}
for (int i = 1; i <= n; i ++) {
int rx = n - i + 1;
sf[rx] = sf[rx + 1] + a[rx];
sj[rx] = sj[rx + 1] + i * a[rx];
}
int q;
cin >> q;
while (q --)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
728 KB |
Output is correct |
6 |
Correct |
2 ms |
856 KB |
Output is correct |
7 |
Correct |
3 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
992 KB |
Output is correct |
9 |
Correct |
4 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1372 KB |
Output is correct |
2 |
Correct |
11 ms |
4312 KB |
Output is correct |
3 |
Correct |
15 ms |
4884 KB |
Output is correct |
4 |
Correct |
26 ms |
6492 KB |
Output is correct |
5 |
Correct |
36 ms |
8276 KB |
Output is correct |
6 |
Correct |
41 ms |
8048 KB |
Output is correct |
7 |
Correct |
35 ms |
8068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
4184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |