This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 1e5;
int n, q, a[N + 1], k;
set<int> num;
struct FenwickTree
{
long long tree[N + 1];
void add(int pos, int val)
{
for (; pos <= n; pos += (pos & (-pos)))
{
tree[pos] += val;
}
}
long long sum(int pos)
{
long long ret = 0;
for (; pos > 0; pos -= (pos & (-pos)))
{
ret += tree[pos];
}
return ret;
}
long long sum(int l, int r)
{
return sum(r) - sum(l - 1);
}
} tree;
void read()
{
cin >> n >> q >> k;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
if (a[i])
{
num.insert(i);
tree.add(i, a[i]);
}
}
}
void solve()
{
while(q--)
{
int t;
cin >> t;
if (t == 1)
{
int i, x;
cin >> i >> x;
tree.add(i, -a[i]);
a[i] = x;
tree.add(i, a[i]);
if (a[i])
{
num.insert(i);
}
}
else if (t == 2)
{
int l, r;
cin >> l >> r;
if (k == 1)
{
continue;
}
vector<int> valid;
while(true)
{
auto it = num.lower_bound(l);
if (it == num.end() || *it > r)
{
for (int i : valid)
{
num.insert(i);
}
break;
}
tree.add(*it, -a[*it]);
a[*it] /= k;
if (a[*it])
{
tree.add(*it, a[*it]);
valid.push_back(*it);
}
num.erase(it);
}
}
else
{
int l, r;
cin >> l >> r;
cout << tree.sum(l, r) << '\n';
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case #" << __ << ":" << '\n';
read();
solve();
}
}
Compilation message (stderr)
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |