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];
int n;
vector<ll> ft;
void init(int N)
{
n = N + 5;
ft.assign(n + 5, 0);
}
void add(ll pos, ll val)
{
for (pos = pos + 1; pos <= n; pos += pos & -pos) ft[pos] += val;
}
ll get(ll pos, ll res = 0)
{
for (pos = pos + 1; pos > 0; pos -= pos & -pos) res += ft[pos];
return res;
}
signed main()
{
OPT
ll n, k;
cin >> n >> k;
init(n);
for(ll i = 1; i <= n; ++i)
cin >> a[i], add(i, a[i]);
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 += get(i + m - 1);
ans -= get(i - 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... |