Segment Tree getting wrong answer

I am getting wrong answer in this question on segment tree. I tried to find out the error but couldn’t find.Could anyone please help me in finding what’s wrong in this code.

Question link : https://codeforces.com/edu/course/2/lesson/4/1/practice/contest/273169/problem/C

My code:

#include <bits/stdc++.h>
#include<thread>
using namespace std;
#define inf 1000000007
#define ll long long int
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vvc vector< vector<char> >
#define vvi vector< vector<int> >
#define vvb vector< vector<bool> >
#define vvpii vector< vector< pair<int,int> > >
#define vll vector<long long int>
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pqpii priority_queue< pair<int,int> ,vector< pair<int,int> >,greater< pair<int,int> > >
#define mii map<int,int>
#define msi map<string,int>
#define mmii multimap<int,int>
#define mmsi multimap<string,int>
#define umii unordered_map<int,int>
#define umsi unordered_map<string,int>
#define ummii unordered_multimap<int,int>
#define ummsi unordered_multimap<string,int>
#define f(i,a,b) for(int i = a; i < b; ++i)
#define fr(i,a,b) for(int i = a; i > b; --i) 

typedef struct Segment_Tree
{
    int left_index,right_index,val;
    struct Segment_Tree *left_child = nullptr,*right_child = nullptr;
    mii mp;
}Segment_Tree;

Segment_Tree * create_segment_tree(int l,int r,vi &vec)
{
    Segment_Tree * temp = new Segment_Tree();
    temp->left_index = l;
    temp->right_index = r;
    if(l == r)
    temp->val = vec.at(l),temp->mp[temp->val] = 1;
    else
    {
        temp->left_child = create_segment_tree(l,(l + r) / 2,vec);
        temp->right_child = create_segment_tree((l + r) / 2 + 1,r,vec);
        temp->val = min(temp->left_child->val , temp->right_child->val);
        for(auto val:temp->left_child->mp)
        temp->mp[val.first] = val.second;
        for(auto val:temp->right_child->mp)
        temp->mp[val.first] += val.second;
    }
    return temp;
}

Segment_Tree * update(Segment_Tree *root,int index,int val)
{
    if(root->left_index == root->right_index && root->left_index == index)
    root->mp[root->val]--,root->val = val,root->mp[val]++;
    else if(index <= root->right_index && index >= root->left_index)
    {
        root->left_child = update(root->left_child,index,val);
        root->right_child = update(root->right_child,index,val);
        root->val = min(root->left_child->val , root->right_child->val);
        root->mp[val] = root->left_child->mp[val];
        root->mp[val] += root->right_child->mp[val];
    }
    return root;
}

int Segment_Tree_min(Segment_Tree * root,int l,int r)
{
    if(root->left_index > r || root->right_index < l)
    return INT_MAX;
    else if(root->left_index >= l && root->right_index <= r)
    return root->val;
    else
    return min(Segment_Tree_min(root->left_child,l,r) , Segment_Tree_min(root->right_child,l,r));
}


int Segment_Tree_frequency(Segment_Tree * root,int l,int r,int val)
{
    if(root->left_index > r || root->right_index < l)
    return 0;
    else if(root->left_index >= l && root->right_index <= r)
    return root->mp[val];
    else
    return Segment_Tree_frequency(root->left_child,l,r,val) + Segment_Tree_frequency(root->right_child,l,r,val);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    vi vec(n);
    f(i,0,n)
    cin>>vec.at(i);
    Segment_Tree * root = create_segment_tree(0,n-1,vec);
    while(m--)
    {
        int type;
        cin>>type;
        if(type == 1)
        {
            int i,v;
            cin>>i>>v;
            if(v != vec.at(i))
            root = update(root,i,v);
            vec.at(i) = v;
        }
        else
        {
            int l,r;
            cin>>l>>r;
            int min_value = Segment_Tree_min(root,l,r-1);
            int frequency_of_minimum_value = Segment_Tree_frequency(root,l,r-1,min_value);
            cout<<min_value<<" "<<frequency_of_minimum_value<<"\n";
        }
    }
    return 0;
}