#include <iostream>
#include <vector>
#define ll long long
using namespace std;
int main() {
ll n, k, q, l, r, m;
cin >> n >> k;
vector<ll> a(n), b(n), c(n), u(k);
for(ll i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
c[i] = (i+1)*a[i];
if(i != 0) b[i]+=b[i-1], c[i]+=c[i-1];
}
cin >> q;
while(q--) {
cin >> m;
if(m == 1) {
for(ll i = 0; i < k; i++) cin >> u[i];
} else {
cin >> l >> r >> m;
l--, r--;
if(2*m <= r-l+1) cout << c[l+m-1]-(l-1 < 0 ? 0 : c[l-1])-l*(b[l+m-1]-(l-1 < 0 ? 0 : b[l-1])) + (b[r-m]-b[l+m-1])*m + (r+2)*(b[r]-(r-m < 0 ? 0 : b[r-m]))-(c[r]-c[r-m]) << "\n";
else cout << c[r-m]-(l-1 < 0 ? 0 : c[l-1])-l*(b[r-m]-(l-1 < 0 ? 0 : b[l-1])) + (b[l+m-1]-b[r-m])*(r-l+2-m) + (r+2)*(b[r]-(l+m-1 < 0 ? 0 : b[l+m-1]))-(c[r]-c[l+m-1]) << "\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
316 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
436 KB |
Output is correct |
5 |
Correct |
8 ms |
504 KB |
Output is correct |
6 |
Correct |
10 ms |
572 KB |
Output is correct |
7 |
Correct |
12 ms |
608 KB |
Output is correct |
8 |
Correct |
14 ms |
596 KB |
Output is correct |
9 |
Correct |
19 ms |
820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
980 KB |
Output is correct |
2 |
Correct |
58 ms |
2072 KB |
Output is correct |
3 |
Correct |
82 ms |
2788 KB |
Output is correct |
4 |
Correct |
135 ms |
4684 KB |
Output is correct |
5 |
Correct |
197 ms |
6616 KB |
Output is correct |
6 |
Correct |
180 ms |
6324 KB |
Output is correct |
7 |
Correct |
222 ms |
6360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
115 ms |
1956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |