This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define Y8o "Sterilizing Spray"
#define maxn 100005
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
using namespace std;
/// okay?
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r)
{
return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() /// ------------------inp_out file!-----------------///
{
if(fopen(Y8o".inp", "r"))
{
freopen(Y8o".inp", "r", stdin);
freopen(Y8o".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void ctime() /// ------------------check time!-----------------///
{
cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
/// okay!
int n, Q, k;
int a[maxn];
struct dl
{
int id, f, s;
} qr[maxn];
pii st[4 * maxn]; /// max + pos
ll st2[4 * maxn]; /// sum
void build(int id = 1, int l = 1, int r = n)
{
if(l == r)
{
st[id] = {a[l], l};
st2[id] = 1ll * a[l];
return ;
}
int mid = (l + r) >> 1;
build(id * 2, l, mid);
build(id * 2 + 1, mid + 1, r);
st[id] = max(st[id * 2], st[id * 2 + 1]);
st2[id] = st2[id * 2] + st2[id * 2 + 1];
}
void update(int i, int val, int id = 1, int l = 1, int r = n)
{
if(i < l || r < i) return ;
if(l == r)
{
st[id] = {val, l};
st2[id] = 1ll * val;
return ;
}
int mid = (l + r) >> 1;
update(i, val, id * 2, l, mid);
update(i, val, id * 2 + 1, mid + 1, r);
st[id] = max(st[id * 2], st[id * 2 + 1]);
st2[id] = st2[id * 2] + st2[id * 2 + 1];
}
pii getma(int u, int v, int id = 1, int l = 1, int r = n)
{
if(v < l || r < u) return {0, 0};
if(u <= l && r <= v) return st[id];
int mid = (l + r) >> 1;
return max( getma(u, v, id * 2, l, mid), getma(u, v, id * 2 + 1, mid + 1, r) );
}
ll getsum(int u, int v, int id = 1, int l = 1, int r = n)
{
if(v < l || r < u) return 0;
if(u <= l && r <= v) return st2[id];
int mid = (l + r) >> 1;
return getsum(u, v, id * 2, l, mid) + getsum(u, v, id * 2 + 1, mid + 1, r);
}
void solve()
{
cin >> n >> Q >> k;
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 1; i <= Q; i ++) cin >> qr[i].id >> qr[i].f >> qr[i].s;
build();
for(int i = 1; i <= Q; i ++)
{
int id = qr[i].id, u = qr[i].f, v = qr[i].s, l = u, r = v;
if(id == 1) update(u, v); /// a[u] = v
else if(id == 2)
{
vector<pii> store;
while(1)
{
pii best = getma(l, r);
if(best.first != 0)
{
store.push_back(best);
update(best.second, 0);
}
else break;
}
for(pii x : store)
{
int val = x.first, pos = x.second;
update(pos, val / k);
}
store.clear();
}
else cout << getsum(l, r) << '\n';
}
}
int main()
{
iof();
int nTest = 1;
// cin >> nTest;
while(nTest --)
{
solve();
}
ctime();
return 0;
}
Compilation message (stderr)
sterilizing.cpp: In function 'void iof()':
sterilizing.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(Y8o".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(Y8o".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |