Distinct characters in range

Can some one please tell me why the query function in my code is not working ?

Problem : https://codeforces.com/contest/1234/problem/D (distinct character queries)

Code :

#include<iostream>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
string s;
int arr[26];
int tree[100010][26];
int test[26];
void build(int id,int l,int r)
{
	int m = (l+r)/2;
	if(l==r){
		tree[id][s[l]-'a']=1;
	}
	else
	{
		build(2*id,l,m);
		build(2*id+1,m+1,r);
		for(int i = 0 ; i < 26 ; i++)
		{
			tree[id][i]=tree[2*id][i]|tree[2*id+1][i];
		}
	}
}
void update(int id,int l,int r,int pos,char val)
{
	int m = (l+r)/2;
	if(l==r){
		tree[id][s[pos]-'a']=0;
		tree[id][val-'a']=1;
		s[pos]=val;
		return;
	}
	else
	{
		if(pos<=m){
			update(2*id,l,m,pos,val);
		}
		else if(pos>m){
			update(2*id+1,m+1,r,pos,val);
		}
		for(int i = 0 ; i < 26 ; i++ ){
			if(tree[2*id][i]==1||tree[2*id+1][i]==1){
				tree[id][i]=1;
			}
			else
			tree[id][i]=0;
		}
	}
}
void dist(int id,int l,int r,int qs,int qe,vector<int> & v)
{
	if(qs>r || qe<l){
		return;
	}
	if(qs<=l && qe>=r){
		for(int i = 0 ; i < 26 ; i++ ){
			if(tree[id][i]==1){
				v[i]=1;
			}
		}
		return ;
	}
	int m = (l+r)/2;
	dist(2*id,l,m,qs,qe,v);
	dist(2*id+1,m+1,r,qs,qe,v);
	for(int i = 0 ; i < 26 ; i++){
		if(tree[2*id][i]==1 || tree[2*id+1][i]==1){
			v[i]=1;
		}
		else
		v[i]=0;
	}
}
int main()
{
	fast;
	cin >> s;
	int query,type,l,r,pos;
	char val;
	int n = s.size();
	build(1,0,n-1);
	cin >> query;
	while(query--)
	{
		cin >> type;
		if(type==2){
			cin >> l >> r;
			l--;
			r--;
			int c =0;
			vector<int>v(26,0);
			dist(1,0,n-1,l,r,v);
			for(int i = 0 ; i < 26 ; i++ ){
				c+=v[i];
			}
			cout<<c<<'\n';
		}
		else{
			cin >> pos >> val;
			pos--;
			update(1,0,n-1,pos,val);
		}
	}
}

Thanks in advance