#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ld long double
#define ar array
#define vc vector
#define aint(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define rep(i,a,b) for(int i = a; i < b; i++)
#define per(i,a,b) for(int i = a; i >= b; i--)
#define trav(a,x) for(auto& a : x)
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " = " << x << endl
const int N = 2e5 + 5;
const int L = 24;
const int inf = 1e9 + 7;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int n;
vector<int> ft;
void init(int N)
{
n = N + 5;
ft.assign(n + 5, 0);
}
void add(int pos, int val)
{
for (pos = pos + 1; pos <= n; pos += pos & -pos) ft[pos] += val;
}
int get(int pos, int res = 0)
{
for (pos = pos + 1; pos > 0; pos -= pos & -pos) res += ft[pos];
return res;
}
void solve(){
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++){
cin >> a[i];
add(i, a[i]);
}
int q;
cin >> q;
while(q--){
int ty, l, r, m;
cin >> ty;
if(ty == 2){
cin >> l >> r >> m;
int ans = 0;
for(int i = l; i + m - 1 <= r; i++){
ans += get(i + m - 1);
ans -= get(i - 1);
}
cout << ans << endl;
}
}
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int T = 1;
while(T--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |