제출 #1281831

#제출 시각아이디문제언어결과실행 시간메모리
1281831ghammazhassanAdvertisement 2 (JOI23_ho_t2)C++20
100 / 100
1511 ms31532 KiB
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
using namespace std;
// #define int long long
#define endl "\n"
#define fi first
#define se second
const int M=1e9+7;
const int inf = 1e9;
const int LOG=20;
const int N=2e5+5;
int n , m , c , w , k , t=1 , q=1 , x , y , z , l , r;

void solve()
{       
    cin >> n;
    vector<pair<int,int>>a(n),b(n);
    for (int i=0;i<n;i++){
        cin >> a[i].fi >> a[i].se;
        b[i]={a[i].se,a[i].fi};
    }
    map<int,int>vi;
    sort(a.begin(),a.end());
    sort(b.rbegin(),b.rend());
    c=0;
    set<pair<int,int>>l;
    l.insert({0,0});
    l.insert({1e9+1,0});
    for (int i=0;i<n;i++){
        x=b[i].se;
        y=b[i].fi;
        auto h2=*l.upper_bound({x,-1});
        int li=1;
        int hi=x;
        int mi=(li+hi)/2;
        while (li<hi){
            if ((*l.lower_bound({mi,-1})).fi!=h2.fi){
                li=mi;
            }
            else{
                hi=mi-1;
            }
            mi=(li+hi+1)/2;
        }
        auto h1=*l.lower_bound({mi,-1});
        if (abs(x-h1.fi)<=h1.se-y or abs(x-h2.fi)<=h2.se-y){
            continue;
        }
        c++;
        l.insert({x,y});
    }
    cout << c << endl;
}
signed main()    
{

    ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
    cin.tie(0), cout.tie(0);//DO NOT USE IN INTERACTIVE
    cout << fixed << setprecision(9);
    srand(time(0));
    // int t=1;
    // cin >> t;
    for (int _=1;_<=t;_++){
        solve();
        q++;
    }
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...