This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define vi vector<ll>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ld long double
#define pii pair<ll, ll>
#define mt make_tuple
#define mn(a, b) a = min(a, b)
#define mx(a, b) a = max(a, b)
using namespace std;
const ll INF = (ll)2e9;
const ll inf = (ll)2e18;
const ld eps = (ld)1e-8;
const ll mod = (ll)998244353;
const ll MAXN = (ll)1e5 + 1;
const ll MAXC = (ll)1e6 + 1;
const ll MAXE = (ll)1000;
const ll MAXLOG = 21;
const ll maxlen = (ll)1e5;
const ll asci = (ll)256;
const ll block = 480;
const ld PI = acos(-1);
const ld e = 2.7182818284;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<
pii,
null_type,
less<pii>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
template <class T>
istream& operator >>(istream &in, vector<T> &arr){
for (T &cnt : arr) {
in >> cnt;
}
return in;
};
struct stree{
vector<pii> t;
void build(ll v, ll tl, ll tr, vi &a) {
if (tl + 1 == tr) return void(t[v] = mp(a[tl], a[tl]));
ll tm = (tl + tr) / 2;
build(2 * v, tl, tm, a);
build(2 * v + 1, tm, tr, a);
t[v] = mp(max(t[2 * v].first, t[2 * v + 1].first), t[2 * v].second + t[2 * v + 1].second);
}
stree(vi &a) {
t.resize(4 * a.size());
build(1, 0, a.size(), a);
}
void div(ll v, ll tl, ll tr, ll l, ll r, ll x) {
if (x == 1) return;
if (tl >= r || l >= tr || !t[v].first) return;
if (tl + 1 == tr) {
t[v].first /= x;
t[v].second /= x;
return;
}
ll tm = (tl + tr) / 2;
div(2 * v, tl, tm, l, r, x);
div(2 * v + 1, tm, tr, l, r, x);
t[v] = mp(max(t[2 * v].first, t[2 * v + 1].first), t[2 * v].second + t[2 * v + 1].second);
}
void pt(ll v, ll tl, ll tr, ll pos, ll x) {
if (tl + 1 == tr) return void(t[v] = mp(x, x));
ll tm = (tl + tr) / 2;
if (pos < tm) pt(2 * v, tl, tm, pos, x);
else pt(2 * v + 1, tm, tr, pos, x);
t[v] = mp(max(t[2 * v].first, t[2 * v + 1].first), t[2 * v].second + t[2 * v + 1].second);
}
ll sum(ll v, ll tl, ll tr, ll l, ll r) {
if (l <= tl && tr <= r) return t[v].second;
if (tl >= r || l >= tr) return 0;
ll tm = (tl + tr) / 2;
return sum(2 * v, tl, tm, l, r) + sum(2 * v + 1, tm, tr, l, r);
}
};
void solve() {
ll n, q, k; cin >> n >> q >> k;
vi a(n); cin >> a;
stree t(a);
while (q--) {
ll s, l, r; cin >> s >> l >> r;
if (s == 1) t.pt(1, 0, n, l - 1, r);
if (s == 2) t.div(1, 0, n, l - 1, r, k);
if (s == 3) cout << t.sum(1, 0, n, l - 1, r) << "\n";
}
}
int main() {
srand(time(0));
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#endif
cout.precision(30);
solve();
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... |