#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
const int N=5e5+99;
int n,q,k,a[N],Sum[N],Max[N];
void merge(int id){
Sum[id]=Sum[id<<1]+Sum[id<<1|1];
Max[id]=max(Max[id<<1],Max[id<<1|1]);
}
void build(int id=1,int l=1,int r=n+1){
if(l+1==r){
Sum[id]=a[l];
Max[id]=a[l];
return ;
}
int mid=(l+r)>>1;
build(id<<1,l,mid);
build(id<<1|1,mid,r);
merge(id);
}
void change(int x,int val,int id=1,int l=1,int r=n+1){
if(r<=x || x<l) return ;
if(l+1==r){
Sum[id]=val;
Max[id]=val;
return ;
}
int mid=(l+r)>>1;
change(x,val,id<<1,l,mid);
change(x,val,id<<1|1,mid,r);
merge(id);
}
int get(int L,int R,int id=1,int l=1,int r=n+1){
if(r<=L || R<=l) return 0;
if(L<=l && r<=R){
return Sum[id];
}
int mid=(l+r)>>1;
return get(L,R,id<<1,l,mid)+get(L,R,id<<1|1,mid,r);
}
void spray(int L,int R,int id=1,int l=1,int r=n+1){
if(Max[id]==0 || r<=L || R<=l) return ;
if(l+1==r){
Sum[id]/=k;
Max[id]/=k;
return ;
}
int mid=(l+r)>>1;
spray(L,R,id<<1,l,mid);
spray(L,R,id<<1|1,mid,r);
merge(id);
}
int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
cin>>n>>q>>k;
f(i,1,n+1) cin>>a[i];
build();
f(i,0,q){
int type,l,r;
cin>>type>>l>>r;
if(type==1){
change(l,r);
}
if(type==2){
spray(l,r+1);
}
if(type==3){
cout<<get(l,r+1)<<'\n';
}
}
}
/*
5 2 3
1 5 8 1 3
2 3 5
3 2 5
*/
Compilation message
cc1plus: error: '::main' must return 'int'