Language: C++

#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <list>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	string S; cin>>S;
	ll q; cin>>q;
	cout<<q<<endl;
	vector<vector<char>> Q(q,vector<char>(3,0));
	REP(i,q){
		REP(j,3){
			cin>>Q[i][j];
		}
	}
	vector<ll> s(n);
	REP(i,n){
		s[i]=S[i]-'a';
	}
	vector<list<int>> num(26);
	REP(i,n){
		num[s[i]].push_back(i+1);
	}
	/*
	REP(i,(signed)num.size()){
		REP(j,(signed)num[i].size()){
			cout<<num[i][j]<<" "; //----------cout----------//
		}
		cout << endl;
	}*/
	
	REP(i,q){
		char a,b,c;
		ll ans=0;
		a=Q[i][0];
		b=Q[i][1];
		c=Q[i][2];
		if(a=='1'){
			b-='0';
			b--;
			c-='a';
			int old=s[b];
			s[b]=c;
			int now=s[b];
			
			auto it=lower_bound(num[old].begin(),num[old].end(),b);
			num[old].erase(it);
			it=lower_bound(num[now].begin(),num[now].end(),b);
			num[old].insert(it,b);
			
		}else{
			b-='0';
			c-='0';
			REP(j,26){
				auto it1=lower_bound(num[j].begin(),num[j].end(),b);
				auto it2=lower_bound(num[j].begin(),num[j].end(),c);
				if(it1-num[j].begin()<=it2-num[j].begin() && it1!=num[j].begin()){
					ans++;
				}
			}
			cout<<ans;
		}
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:70:39: error: no match for 'operator-' (operand types are 'std::_List_iterator<int>' and 'std::__cxx11::list<int>::iterator')
   70 |                                 if(it1-num[j].begin()<=it2-num[j].begin() && it1!=num[j].begin()){
      |                                    ~~~^~~~~~~~~~~~~~~
      |                                    |               |
      |                                    |               _List_iterator<[...]>
      |                                    _List_iterator<[...]>
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:70:53: note:   'std::_List_iterator<int>' is not derived from 'const std::reverse_iterator<_Iterator>'
   70 |                                 if(it1-num[j].begin()<=it2-num[j].begin() && it1!=num[j].begin()){
      |                                                     ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:70:53: note:   'std::_List_iterator<int>' is not derived from 'const std::move_iterator<_IteratorL>'
   70 |                                 if(it1-num[j].begin()<=it2-num[j].begin() && it1!=num[j].begin()){
      |                                                     ^
a.cc:70:59: error: no match for 'operator-' (operand types are 'std::_List_iterator<int>' and 'std::__cxx11::list<int>::iterator')
   70 |                                 if(it1-num[j].begin()<=it2-num[j].begin() && it1!=num[j].begin()){
      |                                                        ~~~^~~~~~~~~~~~~~~
      |                                                        |               |
      |                                                        |               _List_iterator<[...]>
      |                                                        _List_iterator<[...]>
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:70:73: note:   'std::_List_iterator<int>' is not derived from 'const std::reverse_iterator<_Iterator>'
   70 |                                 if(it1-num[j].begin()<=it2-num[j].begin() && it1!=num[j].begin()){
      |                                                                         ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:70:73: note:   'std::_List_iterator<int>' is not derived from 'const std::move_iterator<_IteratorL>'
   70 |                                 if(it1-num[j].begin()<=it2-num[j].begin() && it1!=num[j].begin()){
      |                                                                         ^