#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
6 ms |
328 KB |
Output is correct |
4 |
Correct |
12 ms |
340 KB |
Output is correct |
5 |
Correct |
17 ms |
456 KB |
Output is correct |
6 |
Correct |
25 ms |
500 KB |
Output is correct |
7 |
Correct |
55 ms |
500 KB |
Output is correct |
8 |
Correct |
53 ms |
560 KB |
Output is correct |
9 |
Correct |
91 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |