#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define u128 unsigned __int128
#define i128 __int128
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define eb emplace_back
#define mt make_tuple
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define ff first
#define ss second
const ll inf = 9e18;
const int iinf = 2e9;
const int N = 1e5;
const ll MOD = 1e9 + 7;
class simple_seg_tree
{
private:
vector<ll> t;
int n;
void build(int v, int tl, int tr, vector<int>& a){
if (tl == tr){
t[v] = a[tl];
return;
}
int tm = tl + tr >> 1;
build(2 * v + 1, tl, tm, a);
build(2 * v + 2, tm + 1, tr, a);
t[v] = t[2 * v + 1] + t[2 * v + 2];
}
ll query(int v, int tl, int tr, int ql, int qr){
if (tl > qr || tr < ql){
return 0ll;
}
if (ql <= tl && tr <= qr)
return t[v];
int tm = tl + tr >> 1;
return query(2 * v + 1, tl, tm, ql, qr) + query(2 * v + 2, tm + 1, tr, ql, qr);
}
void assign(int v, int tl, int tr, int pos, int val){
if (tl == tr){
t[v] = val;
return;
}
int tm = tl + tr >> 1;
if (pos <= tm)
assign(2 * v + 1, tl, tm, pos, val);
else
assign(2 * v + 2, tm + 1, tr, pos, val);
t[v] = t[2 * v + 1] + t[2 * v + 2];
}
public:
simple_seg_tree(vector<int>& a, const int & size){
n = size;
t.resize(4 * n);
build(0, 0, n - 1, a);
}
ll query(int l, int r){
return query(0, 0, n - 1, l, r);
}
void assign(int pos, int val){
assign(0, 0, n - 1, pos, val);
}
};
void solution(){
int k, n, q;
cin >> n >> q >> k;
vector<int> c(n);
for (int i = 0; i < n; ++i)
cin >> c[i];
if (n <= 3000 && q <= 3000){
for (int i = 0; i < q; ++i){
int t, l, r;
cin >> t >> l >> r;
--l; --r;
if (t == 1){
++r;
c[l] = r;
} else if (t == 2){
for (int i = l; i <= r; ++i)
c[i] /= k;
} else{
ll ans = 0;
for (int i = l; i <= r; ++i)
ans += c[i];
cout << ans << '\n';
}
}
} else if (k == 1){
simple_seg_tree seg(c, n);
for (int i = 0; i < q; ++i){
int t, l, r;
cin >> t >> l >> r;
--l; --r;
if (t == 1){
++r;
seg.assign(l, r);
} else if (t == 3){
cout << seg.query(l, r) << '\n';
}
}
}
}
signed main(/* Kurmankul Nurislam */){
//freopen("fcolor.in", "r", stdin);
//freopen("fcolor.out", "w", stdout);
cin.tie(nullptr) -> sync_with_stdio(false);
int t = 1;
//cin >> t;
while (t--){
solution();
//cout << '\n';
}
}
# | 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... |