This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while (c < '0' || c > '9')
    {
        c = getchar_unlocked();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + c - '0';
        c = getchar_unlocked();
    }
    return x;
}
void phongbeo();
const int inf = 1e9;
const int mod2 = 1e9 + 7;
const int  mod1 = 998244353;
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a, b, c;
};
struct id
{
    int a, b, c, d;
};
struct ie
{
    int a, b, c, d, e;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int  i, s10, s12,k1,k2,k3,s11,t,lim,w,l,r;
int kk;
int el = 19;
main()
{
    if(fopen(task".inp","r"))
    {
        fin(task);
        fou(task);
    }
    NHP
    /// cin>>s1;
///modwwe
    phongbeo();
    // checktime
}
set<int> s[400001];
set<int> cs;
vector<int> v;
vector<int> v2;
ib a[200001];
ib b[200001];
vector<int> sort1,sort2;
priority_queue<int,vector<int>>ask;
struct IT
{
    ib t[1600001];
    ib mer(ib a,ib b)
    {
        if(a.a<b.a) return a;
        else return b;
    }
    void upd(int node,int l,int r,int l1,int x)
    {
        if(l==r)
        {
            t[node].a=x;
            t[node].b=l;
            return;
        }
        int mid=l+r>>1;
        if(l1<=mid)
            upd(node<<1,l,mid,l1,x);
        else upd(node<<1|1,mid+1,r,l1,x);
        t[node]=mer(t[node<<1],t[node<<1|1]);
    }
    ib get(int node,int l,int r,int l1,int r1)
    {
        if(l>r1||r<l1||t[node].a==inf) return {inf,inf} ;
        if(l>=l1&&r<=r1) {
                return t[node];}
        int mid=l+r>>1;
        return mer(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1));
    }
} st;
void phongbeo()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i].a>>a[i].b,sort1.pb(a[i].a),sort2.pb(a[i].b);
    for(int i=1; i<=n; i++)
        cin>>b[i].a>>b[i].b,sort1.pb(b[i].a),sort2.pb(b[i].b);
    sort(sort1.begin(),sort1.end());
    sort(sort2.begin(),sort2.end());
    for(int i=1; i<=n; i++)
        a[i].a=lower_bound(sort1.begin(),sort1.end(),a[i].a)-sort1.begin()+1,
            a[i].b=lower_bound(sort2.begin(),sort2.end(),a[i].b)-sort2.begin()+1,
                b[i].a=lower_bound(sort1.begin(),sort1.end(),b[i].a)-sort1.begin()+1,
                    b[i].b=lower_bound(sort2.begin(),sort2.end(),b[i].b)-sort2.begin()+1;
    k=n*2;
    for(int i=n; i>=1; --i)
        s[b[i].a].insert(b[i].b),
        cs.insert(b[i].b);
    for(int i=1; i<=4*k; i++)
        st.t[i]= {inf,inf};
    for(int i=1; i<=n; i++)
    {
        auto it=s[a[i].a].lower_bound(a[i].b);
        if(it==s[a[i].a].end())
            ask.push(a[i].b);
        else
        {
            st.upd(1,1,k,*it,a[i].b);
            s[a[i].a].erase(it);
            cs.erase(*it);
        }
    }
    for(auto x:cs)
        v.pb(x);
    reverse(v.begin(),v.end());
    l=0;
    while(!ask.empty())
    {
        int x=ask.top();
                    s4++;
        ask.pop();
        if(v[l]>=x)
        {
            l++;
            continue;
        }
        else
        {
            ib xx=st.get(1,1,k,x,k);
            ask.push({xx.a});
            st.upd(1,1,k,xx.b,inf);
        }
    }
    cout<<s4;
}
Compilation message (stderr)
worst_reporter2.cpp:69:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   69 | main()
      | ^~~~
worst_reporter2.cpp: In member function 'void IT::upd(int, int, int, int, int)':
worst_reporter2.cpp:106:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |         int mid=l+r>>1;
      |                 ~^~
worst_reporter2.cpp: In member function 'ib IT::get(int, int, int, int, int)':
worst_reporter2.cpp:117:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  117 |         int mid=l+r>>1;
      |                 ~^~
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
worst_reporter2.cpp:73:9: note: in expansion of macro 'fin'
   73 |         fin(task);
      |         ^~~
worst_reporter2.cpp:14:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define fou(x) freopen(x".out","w",stdout)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~
worst_reporter2.cpp:74:9: note: in expansion of macro 'fou'
   74 |         fou(task);
      |         ^~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |