Language: C++

//Bismillahirrahmanirrahim

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 200005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,tree[li*4];
int cev;
string s;
PIII p[li];
vector<int> v;

inline void update(int node,int start,int end,int l,int r,int val){
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){tree[node]+=val;return;}
	update(node*2,start,mid,l,r,val),update(node*2+1,mid+1,end,l,r,val);
	tree[node]=tree[node*2]+tree[node*2+1];
}

inline int query(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return 0;
	if(start>=l && end<=r){return tree[node];}
	return query(node*2,start,mid,l,r)+query(node*2+1,mid+1,end,l,r);
}

inline void update1(int node,int start,int end,int l,int r,int val){
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){tree[node]+=val;return;}
	update1(node*2,start,mid,l,r,val),update1(node*2+1,mid+1,end,l,r,val);
	tree[node]=max(tree[node*2],tree[node*2+1]);
}

inline int query1(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return 0;
	if(start>=l && end<=r){return tree[node];}
	return max(query1(node*2,start,mid,l,r),query1(node*2+1,mid+1,end,l,r));
}

int32_t main(void){
	scanf("%lld",&n);
	FOR{
		scanf("%lld %lld",&p[i].fi,&p[i].se.fi);
		p[i].se.se=i;
	}
	sort(p+1,p+n+1);
	FOR{
		update(1,1,n,p[i].se.fi,p[i].se.fi,1);
	}
	for(int i=n;i>=1;i--){
		update(1,1,n,p[i].se.fi,p[i].se.fi,-1);
		a[p[i].se.se]=query(1,1,n,1,p[i].se.fi);
	}
	memset(tree,0,sizeof(tree));
	FOR{
		update(1,1,n,p[i].se.fi,p[i].se.fi,1);
	}
	FOR{
		update(1,1,n,p[i].se.fi,p[i].se.fi,-1);
		a[p[i].se.se]+=query(1,1,n,p[i].se.fi,n);
	}
	memset(tree,0,sizeof(tree));
	FOR{
		update1(1,1,n,p[i].se.fi,p[i].se.fi,a[p[i].se.se]);
	}
	FOR{
		update1(1,1,n,p[i].se.fi,p[i].se.fi,-a[p[i].se.se]);
		a[p[i].se.se]=max(a[p[i].se.se],query1(1,1,n,p[i].se.fi,n));
	}
	FOR printf("%lld\n",a[i]+1);
	return 0;
}



Compiler output:
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:6:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::__cxx11::basic_string<char>::_Alloc_hider::~_Alloc_hider()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = char]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/basic_string.h:186:14: note: called from here
  186 |       struct _Alloc_hider : allocator_type // TODO check __is_final
      |              ^~~~~~~~~~~~