Language: C++

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'

int a[200005+5];
int arr[200005+5];
int st[6*(200005+5)];
vector<int> v[200005+5];
int ans[200005+5];
int cnt[200005+5];
multiset<int> pp[200005+5];

void build(int node,int start,int end)
{
    if(start==end)
    {
        st[node]=arr[start];
        return;
    }
    int mid=(start+end)/2;
    build(2*node,start,mid);
    build(2*node+1,mid+1,end);
    st[node]=st[2*node]+st[2*node+1];
}

ll query(int node,int start,int end,int l,int r)
{
    if(l<=start&&end<=r)  return st[node];
    if(r<start||l>end) return 0;
    int mid=(start+end)/2;
    ll child1=query(2*node,start,mid,l,r);
    ll child2=query(2*node+1,mid+1,end,l,r);
    return max(child1,child2);
}

void update(int node,int start,int end,int index,int val)
{
    if(start==end)
    {
        st[node]=val;
        arr[index]=val;
    }
    else
    {
        int mid=(start+end)/2;
        if(start<=index&&index<=mid) update(2*node,start,mid,index,val);
        else update(2*node+1,mid+1,end,index,val);
        st[node]=max(st[2*node],st[2*node+1]);
    }
}

void dfs(int r,int par)
{
   // ffor(i,1,11) cout<<a[i]<<" ";
   // cout<<endl;
    int x=a[r];
    int num=query(1,0,200005,0,x-1);
    ans[r]=max({num+1,query(1,0,200005,x,200005)});
    pp[x].insert(ans[r]);
    update(1,0,200005,x,*pp[x].rbegin());
    
  //  update(1,0,200005,x,1);
    
    cnt[x]++;
    for(auto i:v[r])
    {
        if(i!=par)
        {
            dfs(i,r);
        }
    }
   // cnt[x]--;
    pp[x].erase(pp[x].find(ans[r]));
    update(1,0,200005,x,*pp[x].rbegin());
}

int main()
{
    ffor(i,0,200005) pp[i].insert(0);
    int n;
    cin>>n;
    map<int,int> m;
    ffor(i,1,n+1)
    {
        cin>>a[i];
        m[a[i]]=1;
    }
    int c=1;
    for(auto i=m.begin();i!=m.end();i++)
    {
        i->ss=c++;
    }
    ffor(i,1,n+1) a[i]=m[a[i]];
    

    ffor(i,0,n-1)
    {
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

  //  ffor(i,1,n+1) cout<<a[i]<<" ";
  //  cout<<endl;
    dfs(1,0);
    ffor(i,1,n+1) cout<<ans[i]<<endl;


    
    return 0;
}



Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:76:15: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   76 |     ans[r]=max({num+1,query(1,0,200005,x,200005)});
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
a.cc:76:15: note:   deduced conflicting types for parameter '_Tp' ('int' and 'long long int')
   76 |     ans[r]=max({num+1,query(1,0,200005,x,200005)});
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided