#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define pll pair<ll, ll>
const int N = 1e5 + 100;
int n, k, q;
ll a[N]; pll fen[N];
void update(int x, ll val){
a[x] += val; ++x; int y = x;
while (x <= n){
fen[x] = {fen[x].F + val, fen[x].S + y * val}; x += x & (-x);
}
}
pll query(int x){
++x; pll val = {0, 0};
while (x > 0){
val = {val.F + fen[x].F, val.S + fen[x].S}; x -= x & (-x);
}
return val;
}
pll range_sum(int l, int r){
if (l > r) return {0, 0};
pll val1 = query(l - 1); pll val2 = query(r);
return {val2.F - val1.F, val2.S - val1.S - l * (val2.F - val1.F)};
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n; ++i){
cin >> a[i]; update(i, a[i]);
}
cin >> q;
for (int i = 0; i < q; ++i){
int u; cin >> u;
if (u == 1){
vector<int> v; v.resize(k);
for (int i = 0; i < k; ++i)
cin >> v[i];
ll cp = a[v[0]];
for (int i = 0; i < k - 1; ++i)
update(v[i], a[v[i + 1]] - a[v[i]]);
update(v[k - 1], a[v[k - 1]] - cp);
}
else{
int l, r, m; cin >> l >> r >> m; --l; --r;
int siz = (r - l + 1);
if (siz >= 2 * m){
ll sum1 = range_sum(l, l + m - 1).S;
ll sum2 = range_sum(l + m, r - m).F;
ll sum3 = (m + 1) * range_sum(r - m + 1, r).F - range_sum(r - m + 1, r).S;
cout << sum1 + sum2 + sum3;
}
else if (m < siz){
if (siz == 2 * m - 1){
ll sum1 = range_sum(l, l + m - 2).S;
ll sum2 = range_sum(l + m - 1, r - m + 1).F;
ll sum3 = m * range_sum(r - m + 2, r).F - range_sum(r - m + 2, r).S;
cout << sum1 + sum2 + sum3;
}
else{
ll sum1 = range_sum(l, l + (siz - m)).S;
ll sum2 = range_sum(l + (siz - m) + 1, r - (siz - m + 1)).F;
ll sum3 = (siz - m + 2) * range_sum(r - (siz - m), r).F - range_sum(r - (siz - m), r).S;
cout << sum1 + sum2 + sum3;
}
}
else cout << range_sum(l, r).F;
cout << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1472 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
42 ms |
3748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |