#include <bits/stdc++.h>
using namespace std;
int a[100005], n, q, k;
long long seg[400005];
set<int> s[400005], t;
void build(int i, int l, int r)
{
if (l==r)
{
seg[i]=a[l];
if (a[l])
s[i].insert(l);
return;
}
int mid=(l+r)/2;
build(i*2, l, mid);
build(i*2+1, mid+1, r);
seg[i]=seg[i*2]+seg[i*2+1];
s[i].insert(s[i*2].begin(), s[i*2].end());
s[i].insert(s[i*2+1].begin(), s[i*2+1].end());
}
void update(int i, int l, int r, int y, int z)
{
if (l==r)
{
seg[i]=a[l]=z;
s[i].erase(l);
if (z)
s[i].insert(l);
return;
}
int mid=(l+r)/2;
if (y<=mid)
update(i*2, l, mid, y, z);
else
update(i*2+1, mid+1, r, y, z);
seg[i]=seg[i*2]+seg[i*2+1];
s[i].erase(l);
if (z)
s[i].insert(l);
}
void spray(int i, int l, int r, int y, int z)
{
if (y<=l && r<=z)
{
t.insert(s[i].begin(), s[i].end());
return;
}
int mid=(l+r)/2;
if (l<=z && y<=mid)
spray(i*2, l, mid, y, z);
if (mid+1<=z && y<=r)
spray(i*2+1, mid+1, r, y, z);
}
long long query(int i, int l, int r, int y, int z)
{
if (y<=l && r<=z)
return seg[i];
int mid=(l+r)/2;
long long res=0;
if (l<=z && y<=mid)
res+=query(i*2, l, mid, y, z);
if (mid+1<=z && y<=r)
res+=query(i*2+1, mid+1, r, y, z);
return res;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q >> k;
for (int i=1; i<=n; i++)
cin >> a[i];
build(1, 1, n);
while (q--)
{
int x, y, z;
cin >> x >> y >> z;
if (x==1)
update(1, 1, n, y, z);
else if (x==2)
{
t.clear();
spray(1, 1, n, y, z);
for (int i:t)
update(1, 1, n, i, a[i]/k);
}
else
cout << query(1, 1, n, y, z) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
19168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5046 ms |
60588 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3342 ms |
21512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5081 ms |
62456 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |