Cod sursa(job #3148555)

Utilizator andiRTanasescu Andrei-Rares andiR Data 2 septembrie 2023 15:49:09
Problema Pachete Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.88 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <iomanip>
#include <vector>

#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front

using namespace std;
ifstream fin ("pachete.in");
ofstream fout ("pachete.out");
typedef long long ll;
const ll Nmax=50000, inf=1e9+5;
using pll=pair<ll, ll>;
struct point{
    int x, y;
};

int n, t;
point o, v[Nmax];
set <int> st1, st2, st3, st4;

bool cmp(point a, point b){
    return a.x<b.x;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    fin>>n;
    fin>>o.x>>o.y;
    for (int i=0; i<n; i++)
        fin>>v[i].x>>v[i].y;
    sort(v, v+n, cmp);
    for (int i=0; i<n; i++){
        ///dreapta-sus
        if (v[i].x>o.x && v[i].y>o.y){
            auto it=st1.upper_bound(v[i].y);
            if (it!=st1.begin()){
                it--;
                st1.erase(it);
            }
                st1.insert(v[i].y);
        }
        ///dreapta-jos
        else if (v[i].x>o.x){
            auto it=st2.upper_bound(v[i].y);
            if (it!=st2.end())
                st2.erase(it);
            st2.insert(v[i].y);
        }
        ///stanga-sus
        else if (v[i].y>o.y){
            auto it=st3.upper_bound(v[i].y);
            if (it!=st3.end())
                st3.erase(it);
            st3.insert(v[i].y);
        }
        ///stanga-jos
        else{
            if (st4.size()==0)
                st4.insert(o.y);
            auto it=st4.upper_bound(v[i].y);
            if (it!=st4.begin()){
                it--;
                st4.erase(it);
            }
            st4.insert(v[i].y);
        }
    }
    fout<<st1.size()+st2.size()+st3.size()+st4.size();
    return 0;
}