// #pragma GCC optimize("O3")
// #pragma GCC optimization("Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, l, r) for (int i = (l); i <= (r); i++)
#define FOD(i, r, l) for (int i = (r); i >= (l); i--)
#define fi first
#define se second
#define pii pair<int, int>
const ll mod = 1e9 + 7;
const int MAXN = 1e5 + 5;
const ll oo = 1e18 + 7;
const int base = 10;
int n, q, k;
int a[MAXN];
struct node{
int mi, mx, sum, sz;
}st[4*MAXN];
int lz[4*MAXN];
node merge(node a, node b){
node c;
c.mi=min(a.mi, b.mi);
c.mx=max(a.mx, b.mx);
c.sum=a.sum+b.sum;
c.sz=a.sz+b.sz;
return c;
}
void build(int id, int l, int r){
lz[id]=-1;
if(l>=r){
st[id]={a[l], a[l], a[l], 1};
return;
}
int mid=(l+r)/2;
build(id*2, l, mid);
build(id*2+1, mid+1, r);
st[id]=merge(st[id*2], st[id*2+1]);
}
void push(int id){
if(lz[id]!=-1){
int val=lz[id];
st[id*2]={val, val, val*st[id*2].sz, st[id*2].sz};
st[id*2+1]={val, val, val*st[id*2+1].sz, st[id*2+1].sz};
lz[id*2]=val;
lz[id*2+1]=val;
lz[id]=-1;
}
}
void update1(int id, int l, int r, int i, int val){
if(l>i || r<i){
return;
}
if(l>=r){
st[id]={val, val, val, 1};
return;
}
int mid=(l+r)/2;
push(id);
update1(id*2, l, mid, i, val);
update1(id*2+1, mid+1, r, i, val);
st[id]=merge(st[id*2], st[id*2+1]);
}
void update2(int id, int l, int r, int i, int j){
if(l>j || r<i){
return;
}
if(l>=i && r<=j){
if(st[id].mi/k==st[id].mx/k){
st[id].mi=st[id].mx=st[id].mi/k;
st[id].sum=(st[id].mi)*st[id].sz;
lz[id]=st[id].mi;
return;
}
}
int mid=(l+r)/2;
push(id);
update2(id*2, l, mid, i, j);
update2(id*2+1, mid+1, r, i, j);
st[id]=merge(st[id*2], st[id*2+1]);
}
node get(int id, int l, int r, int i, int j){
if(l>j || r<i){
return{oo, -oo, 0, 0};
}
if(l>=i && r<=j){
return st[id];
}
int mid=(l+r)/2;
push(id);
return merge(get(id*2, l, mid, i, j), get(id*2+1, mid+1, r, i, j));
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("test.txt", "r", stdin);
// freopen("o2.out", "w", stdout);
if(fopen(".inp", "r")){
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> n >> q >> k;
FOR(i, 1, n){
cin >> a[i];
}
build(1, 1, n);
while(q--){
int t;
cin >> t;
if(t==1){
int i, val;
cin >> i >> val;
update1(1, 1, n, i, val);
}
else if(t==2){
int l, r;
cin >> l >> r;
if(k==1) continue;
update2(1, 1, n, l, r);
}
else{
int l, r;
cin >> l >> r;
cout << get(1, 1, n, l, r).sum << '\n';
}
}
return 0;
}
Compilation message (stderr)
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:110:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
110 | freopen(".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:111:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
111 | freopen(".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... |