Language: C++

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 2e5+100;
const int mod = 1e9+7;
struct data
{
	int ind,val;
};
bool cmp1(data a,data b){
	if(a.val==b.val) return(a.ind>b.ind);
	return(a.val<b.val);
}
bool cmp2(data a,data b){
	return(a.ind<b.ind);
}
int segtree[4*upperlimit];
data arr[upperlimit];
int ans[upperlimit];
vi adj[upperlimit];
bool visited[upperlimit];
int n;
void update(int node,int i,int j,int ind,int v){
	if(i==j){
		segtree[node]=v;
		return;
	}
	int mid=(i+j)>>1;
	if(ind<=mid) update(2*node,i,mid,ind,v);
	else update(2*node+1,mid+1,j,ind,v);
	segtree[node]=max(segtree[2*node],segtree[2*node+1]);
}
int query(int node,int i,int j,int l,int r){
	if((i>r)||(l>j)||(i>j)||(l>r)) return 0;
	if((i>=l)&&(j<=r)) return segtree[node];
	int mid=(i+j)>>1;
	return max(query(2*node,i,mid,l,r),query(2*node+1,mid+1,j,l,r));
}
void dfs(int node){
	visited[node]=true;
	int answer=query(1,1,n,1,arr[node].val)+1;
	ans[node]=max(answer,segtree[1]);
	update(1,1,n,arr[node].val,answer);
	for(int i = 0; i < adj[node].size(); i++){
		if(! visited[adj[node][i]]) dfs(adj[node][i]);
	}
	update(1,1,n,arr[node].val,0);
}
int main() {
	sd(n);
	for(int i = 1; i <= n; i++){
		sd(arr[i].val);
		arr[i].ind=i;
	}
	sort(arr+1,arr+n+1,cmp1);
	for(int i = 1; i <= n; i++) arr[i].val=i;
	sort(arr+1,arr+n+1,cmp2);
	int a,b;
	for(int i = 1; i < n; i++){
		sd(a);sd(b);
		adj[a].pb(b);adj[b].pb(a);
	}
	dfs(1);
	for(int i = 1; i <= n; i++) pdn(ans[i]);
	return 0;
}

Compiler output:
a.cc:42:11: error: reference to 'data' is ambiguous
   42 | bool cmp1(data a,data b){
      |           ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:38:8: note:                 'struct data'
   38 | struct data
      |        ^~~~
a.cc:42:18: error: reference to 'data' is ambiguous
   42 | bool cmp1(data a,data b){
      |                  ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:38:8: note:                 'struct data'
   38 | struct data
      |        ^~~~
a.cc:42:24: error: expression list treated as compound expression in initializer [-fpermissive]
   42 | bool cmp1(data a,data b){
      |                        ^
a.cc:46:11: error: reference to 'data' is ambiguous
   46 | bool cmp2(data a,data b){
      |           ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:38:8: note:                 'struct data'
   38 | struct data
      |        ^~~~
a.cc:46:18: error: reference to 'data' is ambiguous
   46 | bool cmp2(data a,data b){
      |                  ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:38:8: note:                 'struct data'
   38 | struct data
      |        ^~~~
a.cc:46:24: error: expression list treated as compound expression in initializer [-fpermissive]
   46 | bool cmp2(data a,data b){
      |                        ^
a.cc:50:1: error: reference to 'data' is ambiguous
   50 | data arr[upperlimit];
      | ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:38:8: note:                 'struct data'
   38 | struct data
      |        ^~~~
a.cc: In function 'void dfs(int)':
a.cc:73:34: error: 'arr' was not declared in this scope
   73 |         int answer=query(1,1,n,1,arr[node].val)+1;
      |                                  ^~~
a.cc: In function 'int main()':
a.cc:84:20: error: 'arr' was not declared in this scope
   84 |                 sd(arr[i].val);
      |                    ^~~
a.cc:12:27: note: in definition of macro 'sd'
   12 | #define sd(x) scanf("%d",&x)
      |                           ^
a.cc:87:14: error: 'arr' was not declared in this scope
   87 |         sort(arr+1,arr+n+1,cmp1);
      |              ^~~