// #cheat_when_I_was_young
// #cheatkhitacontre #khionhatoicheat
// #thaycuckythatvong
#include "bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
const int NM = 1e6 + 5;
int n, k, q, a[NM], p1[NM], p2[NM], p3[NM];
int get_sum1(int l, int r) {
if (l > r) return 0;
return p1[r] - p1[l-1];
}
int get_sum2(int l, int r) {
if (l > r) return 0;
return p2[r] - p2[l-1] - get_sum1(l, r) * (l-1);
}
int get_sum3(int l, int r) {
if (l > r) return 0;
return p3[l] - p3[r+1] - get_sum1(l, r) * (n-r);
}
signed main() {
IOS;
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
p1[i] = p1[i-1] + a[i];
p2[i] = p2[i-1] + a[i] * i;
}
for (int i = n; i >= 1; --i) p3[i] = p3[i+1] + a[i] * (n-i+1);
cin >> q;
while (q--) {
int type;
cin >> type;
if (type == 1) {
int x;
for (int i = 1; i <= k; ++i) cin >> x;
continue;
}
int l, r, m;
cin >> l >> r >> m;
if (r-l+1 < m) {
cout << "0\n";
continue;
}
int u, v, d = r-l+1-m;
u = l+d;
v = r-d;
cout << get_sum2(l, u-1) + get_sum1(u, v) * (d+1) + get_sum3(v+1, r) << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
1724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
4336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |