#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;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
46 ms |
496 KB |
Output is correct |
3 |
Correct |
155 ms |
772 KB |
Output is correct |
4 |
Correct |
361 ms |
588 KB |
Output is correct |
5 |
Correct |
630 ms |
604 KB |
Output is correct |
6 |
Correct |
1102 ms |
648 KB |
Output is correct |
7 |
Correct |
1407 ms |
652 KB |
Output is correct |
8 |
Correct |
1971 ms |
704 KB |
Output is correct |
9 |
Execution timed out |
2076 ms |
852 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2019 ms |
3128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2049 ms |
3412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |