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>
#define endl '\n'
using namespace std;
const int MAXN = 1e4 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, k, a[MAXN];
void read_array()
{
cin >> n >> k;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
}
}
long long answer(int l, int r, int m)
{
long long ans = 0;
for (int i = l; i <= r; ++ i)
{
long long cnt = m;
long long before = i - l, after = r - i;
if(before < m)cnt -= m - before - 1;
if(i > r - m + 1)cnt -= m - after - 1;
///cout << i << " / " << cnt << endl;
ans += 1ll * a[i] * cnt;
}
return ans;
}
void queries()
{
int q;
cin >> q;
int type, l, r, m, x;
while(q --)
{
cin >> type;
if(type & 1)
{
cin >> x;
continue;
}
else
{
cin >> l >> r >> m;
cout << answer(l, r, m) << endl;
}
}
}
int main()
{
speed();
read_array();
queries();
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... |