#include <bits/stdc++.h>
using namespace std;
#define fori(i,sta,fin) for(ll i=sta;i<fin;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
#define MOD 1000000007
int main() {
int n, k;
cin >> n >> k;
vector<int>vec(n);
for (int i = 0; i < n; i++)
cin >> vec[i];
vector<ll>pre(n);
pre[0] = vec[0];
for (int i = 1; i < n; i++)
pre[i] = pre[i - 1] + vec[i];
vector<ll>ppre(n);
ppre[0] = pre[0];
for (int i = 1; i < n; i++)
ppre[i] = ppre[i - 1] + pre[i];
vector<ll>suf(n);
suf[0] = vec[n-1];
for (int i = 1; i < n; i++)
suf[i] = suf[i - 1] + vec[n-i-1];
vector<ll>ssuf(n);
ssuf[0] = suf[0];
for (int i = 1; i < n; i++)
ssuf[i] = ssuf[i - 1] + suf[i];
int q;
cin >> q;
while (q--) {
int f;
cin >> f;
if (f == 2) {
int l, r, k;
cin >> l >> r >> k;
l--, r--;
ll ans = 0;
int n1 = r - l + 1;
int t = n1 - k + 1;
ans += ssuf[n - l - 1] - ssuf[n - (l + t) - 1] - t * suf[n - (l + t) - 1];
ans += ppre[r] - ppre[r - t] - pre[r - t] * t;
int r1 = r - t + 1;
int l1 = l + t - 1;
int n2 = r1 - l1 - 1;
ans += n2 * t;
cout << ans << endl;
}
else {
int a1;
cin >> a1;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
1264 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
2120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |