#include <bits/stdc++.h>
using namespace std;
void setup()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
struct SEGMENT_TREE
{
long long tree[400000];
inline void Set(int ind, int l, int r, int x, int v)
{
if (r < x || x < l)
{
return;
}
if (l == r)
{
tree[ind] = v;
return;
}
int m = (l + r) >> 1;
Set(ind << 1, l, m, x, v);
Set(ind << 1 | 1, m + 1, r, x, v);
tree[ind] = tree[ind << 1] + tree[ind << 1 | 1];
}
inline void Update(int ind, int l, int r, int x, int y, int v)
{
if (r < x || y < l || tree[ind] == 0)
{
return;
}
if (l == r)
{
tree[ind] /= v;
return;
}
int m = (l + r) >> 1;
Update(ind << 1, l, m, x, y, v);
Update(ind << 1 | 1, m + 1, r, x, y, v);
tree[ind] = tree[ind << 1] + tree[ind << 1 | 1];
}
inline long long Get(int ind, int l, int r, int x, int y)
{
if (r < x || y < l)
{
return 0;
}
if (x <= l && r <= y)
{
return tree[ind];
}
int m = (l + r) >> 1;
return Get(ind << 1, l, m, x, y) + Get(ind << 1 | 1, m + 1, r, x, y);
}
} st;
int n, q, k, a, b, c;
int main()
{
setup();
cin >> n >> q >> k;
for (int i = 0; i < n; ++i)
{
cin >> a;
st.Set(1, 1, n, i + 1, a);
}
while (q--)
{
cin >> a >> b >> c;
if (a == 1)
{
st.Set(1, 1, n, b, c);
}
else if (a == 2 && k != 1)
{
st.Update(1, 1, n, b, c, k);
}
else if (a == 3)
{
cout << st.Get(1, 1, n, b, c) << "\n";
}
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |