#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) "[" #x " = " << (x) << "]"
///#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}
const int N = 2e5+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;
struct SMT{
vector<ll> st; int trsz;
SMT(int n = 0): trsz(n), st((n << 2 | 1)) {}
void update(int id, int l, int r, int u, int v, int val){
if(l == r){
st[id] /= val;
}
else{
int m = l+r>>1;
if(st[id << 1] && u <= m) update(id << 1, l, m, u, v, val);
if(st[id << 1|1] && v > m) update(id << 1|1, m+1 ,r, u, v, val);
st[id] = st[id << 1] + st[id << 1|1];
}
}
void fix(int id, int l, int r, int x, int val){
if(l == r){
st[id] = val;
}
else{
int m = l+r>>1;
if(x <= m)
fix(id << 1, l, m, x, val);
else fix(id << 1|1, m+1, r, x, val);
st[id] = st[id << 1] + st[id << 1|1];
}
}
ll get(int id, int l, int r, int u, int v){
if(l >= u && r <= v) return st[id];
int m = l+r>>1;
return (u <= m ? get(id << 1, l, m, u, v) : 0ll) + (v > m ? get(id << 1|1, m+1, r, u, v) : 0ll);
}
void upd(int l, int r, int val){
if(val > 1)
update(1, 1, trsz, l, r, val);
}
void fix(int x, int val){
fix(1, 1, trsz, x, val);
}
ll query(int l, int r){
return get(1, 1, trsz, l, r);
}
};
void solve()
{
int n,q,k; cin >> n >> q >> k;
SMT st(n);
FOR(i, 1, n){
int x; cin >> x;
st.fix(i, x);
}
while(q--){
int op,l,r; cin >> op >> l >> r;
(op == 1 ? st.fix(l, r) : (op == 2 ? st.upd(l, r, k) : (void) (cout << st.query(l, r) << "\n")));
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
Compilation message (stderr)
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
106 | freopen(name".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | freopen(name".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... |