This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
/// author: LilPluton auuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
#define OPT ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define intt long long
#define arr array
#define vll vector<ll>
#define fi first
#define se second
#define rep(i,j,k) for(int i = j; i <= k; ++i)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define endll '\n'
using namespace std;
const intt N = 2e5 + 6;
const intt mod = 1e9 + 7;
int a[N], t[N * 4];
void build(ll node,ll l, ll r)
{
if(l == r)
{
t[node] = a[l];
return;
}
ll mid = (l + r) / 2;
build(node * 2, l, mid);
build(node * 2 + 1, mid + 1, r);
t[node] = t[node * 2] + t[node * 2 + 1];
}
ll getans(ll node,ll tl,ll tr,ll l, ll r)
{
if(l > r)
return 0;
if(l <= tl && tr <= r)
return t[node];
ll mid = (tl + tr) / 2;
ll q1 = getans(node * 2, tl, mid, l, min(mid, r));
ll q2 = getans(node * 2 + 1, mid + 1, tr, max(mid + 1, l), r);
return q1 + q2;
}
signed main()
{
OPT
ll n, k;
cin >> n >> k;
for(ll i = 1; i <= n; ++i)
cin >> a[i];
build(1,1,n);
ll q;
cin >> q;
while(q--)
{
ll t;
cin >> t;
if(t == 1)
{
ll p;
cin >> p;
}
else
{
ll l, r, m, ans = 0;
cin >> l >> r >> m;
for(ll i = l; i + m - 1 <= r; ++i)
{
ans += getans(1, 1, n, i, i + m - 1);
}
cout << ans << endll;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |