#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0); //cin.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 200005
#define mod 1000000007
#define INF 10000000000000
struct node{
node *left, *right;
ll val;
node(ll v=0, node *l=NULL, node *r=NULL): left(l), right(r), val(v) {}
void build(ll l, ll r)
{
if(l==r)
return;
left = new node();
right = new node();
ll mid=(l+r)>>1;
left->build(l,mid);
right->build(mid+1,r);
}
node* update(ll l, ll r, ll idx, ll v)
{
if(r<idx or l>idx)
return this;
if(l==r){
node *ret = new node(val, left, right);
ret->val+=v;
return ret;
}
ll mid=(l+r)>>1;
node *ret=new node(val);
ret->left=left->update(l,mid,idx,v);
ret->right=right->update(mid+1,r,idx,v);
ret->val=ret->left->val+ret->right->val;
return ret;
}
ll query(ll l, ll r, ll i, ll j)
{
if(r<i or j<l)
return 0;
if(i<=l and r<=j)
return val;
ll mid=(l+r)>>1;
return left->query(l,mid,i,j)+right->query(mid+1,r,i,j);
}
}*root[MX];
int main()
{
fast_io;
ll n,m,t,i,j,k,a,b,c,cs=1;
//freopen(input.txt, r, stdin);
//freopen(output.txt, w, stdout);
root[0]=new node();
cin>> n;
ll num[n+1];
root[0]->build(1,10005);
for(i=1;i<=n;i++){
cin>> a;
num[i]=a;
root[i]=root[i-1]->update(1,10005,a,1);
}
cin>> t;
while(t--){
cin>> m;
if(m==0){
cin>> a >> b;
//root[a]=root[a-1]->update(1,10005,num[a],-1);
root[a]=root[a-1]->update(1,10005,b,1);//Wrong Update
num[a]=b;
}
else{
cin>> a >> b >> c;
ll p1=root[a-1]->query(1,10005,c+1,10005);
ll p2=root[b]->query(1,10005,c+1,10005);
cout<< p2-p1 << endl;
}
}
return 0;
}
I2luY2x1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TsKICAgIH0KCiAgICBub2RlKiB1cGRhdGUobGwgbCwgbGwgciwgbGwgaWR4LCBsbCB2KQogICAgewogICAgICAgIGlmKHI8aWR4IG9yIGw+aWR4KQogICAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBpZihsPT1yKXsKICAgICAgICAgICAgbm9kZSAqcmV0ID0gbmV3IG5vZGUodmFsLCBsZWZ0LCByaWdodCk7CiAgICAgICAgICAgIHJldC0+dmFsKz12OwogICAgICAgICAgICByZXR1cm4gcmV0OwogICAgICAgIH0KICAgICAgICBsbCBtaWQ9KGwrcik+PjE7CiAgICAgICAgbm9kZSAqcmV0PW5ldyBub2RlKHZhbCk7CiAgICAgICAgcmV0LT5sZWZ0PWxlZnQtPnVwZGF0ZShsLG1pZCxpZHgsdik7CiAgICAgICAgcmV0LT5yaWdodD1yaWdodC0+dXBkYXRlKG1pZCsxLHIsaWR4LHYpOwogICAgICAgIHJldC0+dmFsPXJldC0+bGVmdC0+dmFsK3JldC0+cmlnaHQtPnZhbDsKICAgICAgICByZXR1cm4gcmV0OwogICAgfQoKICAgIGxsIHF1ZXJ5KGxsIGwsIGxsIHIsIGxsIGksIGxsIGopCiAgICB7CiAgICAgICAgaWYocjxpIG9yIGo8bCkKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgaWYoaTw9bCBhbmQgcjw9aikKICAgICAgICAgICAgcmV0dXJuIHZhbDsKICAgICAgICAKICAgICAgICBsbCBtaWQ9KGwrcik+PjE7CiAgICAgICAgcmV0dXJuIGxlZnQtPnF1ZXJ5KGwsbWlkLGksaikrcmlnaHQtPnF1ZXJ5KG1pZCsxLHIsaSxqKTsKICAgIH0KCn0qcm9vdFtNWF07CgoKCmludCBtYWluKCkKewoKICAgIGZhc3RfaW87CiAgICBsbCBuLG0sdCxpLGosayxhLGIsYyxjcz0xOwogICAgCiAgICAvL2ZyZW9wZW4oaW5wdXQudHh0LCByLCBzdGRpbik7CiAgICAvL2ZyZW9wZW4ob3V0cHV0LnR4dCwgdywgc3Rkb3V0KTsKCgogICAgcm9vdFswXT1uZXcgbm9kZSgpOwogICAgCiAgICBjaW4+PiBuOwogICAgbGwgbnVtW24rMV07CiAgICByb290WzBdLT5idWlsZCgxLDEwMDA1KTsKCiAgICBmb3IoaT0xO2k8PW47aSsrKXsKICAgICAgICBjaW4+PiBhOwogICAgICAgIG51bVtpXT1hOwogICAgICAgIHJvb3RbaV09cm9vdFtpLTFdLT51cGRhdGUoMSwxMDAwNSxhLDEpOwogICAgfQoKICAgIGNpbj4+IHQ7CiAgICB3aGlsZSh0LS0pewogICAgICAgIGNpbj4+IG07CiAgICAgICAgaWYobT09MCl7CiAgICAgICAgICAgIGNpbj4+IGEgPj4gYjsKICAgICAgICAgICAgLy9yb290W2FdPXJvb3RbYS0xXS0+dXBkYXRlKDEsMTAwMDUsbnVtW2FdLC0xKTsKICAgICAgICAgICAgcm9vdFthXT1yb290W2EtMV0tPnVwZGF0ZSgxLDEwMDA1LGIsMSk7Ly9Xcm9uZyBVcGRhdGUKICAgICAgICAgICAgbnVtW2FdPWI7CiAgICAgICAgfQogICAgICAgIGVsc2V7CiAgICAgICAgICAgIGNpbj4+IGEgPj4gYiA+PiBjOwogICAgICAgICAgICBsbCBwMT1yb290W2EtMV0tPnF1ZXJ5KDEsMTAwMDUsYysxLDEwMDA1KTsKICAgICAgICAgICAgbGwgcDI9cm9vdFtiXS0+cXVlcnkoMSwxMDAwNSxjKzEsMTAwMDUpOwogICAgICAgICAgICBjb3V0PDwgcDItcDEgPDwgZW5kbDsKICAgICAgICB9CiAgICB9CgogICAgcmV0dXJuIDA7Cn0=