Problem:
G: Human Seperation
問題文
単位円の上に人が $10^6$ 人、等間隔に立っています。
$t = \frac{2\pi}{10^6}$ として、$i$ 番目の人は 座標 $(\cos{(it)}, \sin{(it)})$ に立っています。
これら $10^6$ 人の中で、非常に仲が悪いペアが $N$ 組あります。
具体的には、$i = 1, \ldots, N$ について、人 $a_i$ と人 $b_i$ は仲が悪いです。
単位円の管理人である松崎くんは、壁を建設することによって仲の悪いペアを全て分断することにしました。
建設する壁は厚さがなく、とてつもなく長いため、直線と同一視することができます。また、壁同士は交わっても構いません。
ただし、人が立っている場所に壁を建設することは出来ません。
壁を建設するにはコストがかかるので、なるべく少ない数の壁で全てのペアを分断したいです。
目的を達成するためには、いくつの壁を建設する必要があるか求めてください。
定式的に問題を言い換えると以下のようになります:
2次元平面上に単位円があり、円周上の2点からなるペアが $N$ 組与えられます。
あなたは平面上に任意に直線を置くことができます。
ただし、どの与えられた点も直線上に存在してはいけません。
全てのペアが、いずれかの直線によって分離されるには、直線を最小で何本置く必要があるか求めてください。
「2点が直線によって分離されている」とは、2点をどのような曲線で結んでも、曲線が直線と交わる状態を指します。
制約
入力は全て整数
$1 \leq N \leq 2 \times 10^5$
$0 \leq a_i < b_i < 10^6$
入力
入力は以下の形式で標準入力から与えられます。
$N$
$a_1$ $b_1$
$:$
$a_N$ $b_N$
出力
答えを1行に出力してください。
入出力例
入力例1
1
0 500000
出力例1
1
円周上の点 $(1, 0)$ と点 $(-1, 0)$ がペアとして与えられます。
ペアは1組しかないので、明らかに1本の直線によって条件を満たすことができます。
入力例2
2
0 333333
333333 666666
出力例2
1
入力例3
5
0 6
1 2
1 8
3 5
4 10
出力例3
2

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i, n) for(ll i=0; i <ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B>
bool chmax(A &a, B b) { return a < b && (a=b, true); }
template <class A, class B>
bool chmin(A &a, B b) { return b < a && (a=b, true); }

void testcase(){
  ll N; cin >> N;
  ll Z = 1000000;
  V<ll> A(Z+1, Z*2);
  REP(i,N){
    ll a,b; cin >> a >> b;
    chmin(A[a], b);
    chmin(A[b], a + Z);
  }
  REP(t,2){
    for(ll i=Z-1; i>=0; i--) chmin(A[i], A[i+1]);
    chmin(A[Z], A[0] + Z);
  }
  V<pair<ll,ll>> dp(Z*2+2, {INF,INF});
  REP(i,Z+1) dp[Z+i] = {0,i};
  for(ll i=Z-1; i>=0; i--){
    ll a = A[i];
    dp[i] = { dp[a].first + 1, dp[a].second };
  }
  ll ans = INF;
  REP(i,Z) if(i <= dp[i].second) chmin(ans, dp[i].first);
  ans = (ans + 1) / 2;
  cout << ans << "\n";
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  testcase();
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 42216
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i, n) for(ll i=0; i <ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B>
bool chmax(A &a, B b) { return a < b && (a=b, true); }
template <class A, class B>
bool chmin(A &a, B b) { return b < a && (a=b, true); }

void testcase(){
  ll N; cin >> N;
  ll Z = 1000000;
  V<ll> A(Z+1, Z*2);
  REP(i,N){
    ll a,b; cin >> a >> b;
    chmin(A[a], b + 1);
    chmin(A[b], a + Z + 1);
  }
  REP(t,2){
    for(ll i=Z-1; i>=0; i--) chmin(A[i], A[i+1]);
    chmin(A[Z], A[0] + Z);
  }
  V<pair<ll,ll>> dp(Z*2+2, {INF,INF});
  REP(i,Z) dp[Z+i] = {0,i};
  for(ll i=Z-1; i>=0; i--){
    ll a = A[i];
    dp[i] = { dp[a].first + 1, dp[a].second };
  }
  ll ans = INF;
  REP(i,Z) if(i <= dp[i].second) chmin(ans, dp[i].first);
  ans = (ans + 1) / 2;
  cout << ans << "\n";
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  testcase();
  return 0;
}
accuracy: 0.14893617021276595
time_ms: 30
memory_kb: 42024
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i, n) for(ll i=0; i <ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B>
bool chmax(A &a, B b) { return a < b && (a=b, true); }
template <class A, class B>
bool chmin(A &a, B b) { return b < a && (a=b, true); }

void testcase(){
  ll N; cin >> N;
  ll Z = 1000000;
  V<ll> A(Z+1, Z*2);
  REP(i,N){
    ll a,b; cin >> a >> b;
    chmin(A[a], b + 1);
    chmin(A[b], a + Z + 1);
  }
  REP(t,2){
    for(ll i=Z-1; i>=0; i--) chmin(A[i], A[i+1]);
    chmin(A[Z], A[0] + Z);
  }
  V<pair<ll,ll>> dp(Z*2+2, {INF,INF});
  REP(i,Z) dp[Z+i] = {0,i};
  for(ll i=Z-1; i>=0; i--){
    ll a = A[i];
    dp[i] = { dp[a].first + 1, dp[a].second };
  }
  ll ans = 0;
  REP(i,Z) if(i <= dp[i].second) chmax(ans, dp[i].first);
  ans = (ans + 1) / 2;
  cout << ans << "\n";
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  testcase();
  return 0;
}
accuracy: 0.14893617021276595
time_ms: 30
memory_kb: 42092
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i, n) for(ll i=0; i <ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B>
bool chmax(A &a, B b) { return a < b && (a=b, true); }
template <class A, class B>
bool chmin(A &a, B b) { return b < a && (a=b, true); }

void testcase(){
  ll N; cin >> N;
  ll Z = 1000000;
  V<ll> A(Z+1, Z*2);
  REP(i,N){
    ll a,b; cin >> a >> b;
    if(a > b) swap(a, b);
    chmin(A[a], b);
    chmin(A[b], a + Z);
  }
  REP(t,2){
    for(ll i=Z-1; i>=0; i--) chmin(A[i], A[i+1]);
    chmin(A[Z], A[0] + Z);
  }
  V<pair<ll,ll>> dp(Z*2+2, {INF,INF});
  REP(i,Z) dp[Z+i] = {0,i};
  for(ll i=Z-1; i>=0; i--){
    ll a = A[i];
    dp[i] = { dp[a].first + 1, dp[a].second };
  }
  ll ans = 0;
  REP(i,Z) if(i <= dp[i].second) chmax(ans, dp[i].first);
  ans = (ans + 1) / 2;
  cout << ans << "\n";
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  testcase();
  return 0;
}
accuracy: 0.3829787234042553
time_ms: 30
memory_kb: 42148
final_rank: 9

code_snippet: // AOJ #2984 Human Seperation
// 2025.5.28

#include <bits/stdc++.h>
using namespace std;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) {
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

const int N = 1000000;
const int INF = N;

int main(){
    int M = Cin();
    vector<int> w(N, INF);
    for(int i = 0; i < M; i++){
        int a = Cin(), b = Cin();
        int d = (b - a + N) % N;
        if(d > N/2) d = N - d, swap(a, b);
        w[a] = min(w[a], d);
        w[b] = min(w[b], (N - d) % N);
    }

    for(int t = 2*N - 1; t >= 0; --t){
        int i = t % N;
        int j = (i + 1) % N;
        w[i] = min(w[i], w[j] + 1);
    }

    int pivot = max_element(w.begin(), w.end()) - w.begin();
    rotate(w.begin(), w.begin() + pivot, w.end());

    vector<pair<int,int>> dp(N, {-1,-1});
    for(int i = 0; i < w[0]; ++i) dp[i] = {0, i};

    int ans = INF;
    for(int i = 0; i < N; ++i){
        int reach = i + w[i];
        if(reach >= N){
            int extra = (N + dp[i].second <= reach ? 1 : 2);
            ans = min(ans, dp[i].first + extra);
        }
        int j = min(reach, N - 1);
        while(dp[j].first == -1){
            dp[j] = {dp[i].first + 1, dp[i].second};
            --j;
        }
    }
    Cout((ans + 1) / 2);
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 14724
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define ALL(v) (v).begin(), (v).end()
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

int main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll N;
    cin >> N;
    vector<vector<ll>> G(1'000'000);
    REP(i,N){
        ll a,b;
        cin >> a >> b;
        G[a].push_back(b);
    }

    set<ll> S;
    ll Ans = 0;
    vector<ll> notch;
    REP(i,1'000'000){
        if(S.find(i)!=S.end()){
            //cout << i << endl;
            S.clear();
            Ans++;
            notch.push_back(i);
        }
        for(ll e:G[i]){
            S.insert(e);
        }
    }

    ll M = notch.size();

    bool c = true;
    REP(i,1'000'000){
        for(ll e:G[i]){
            if(i < notch[0] && notch[M-1] <= e){
                c = false;
            }
        }
    }

    if(!c){
        Ans++;
    }

    Ans = (Ans+1)/2;

    cout << Ans << endl;
    
    return 0;
}
accuracy: 0.6170212765957447
time_ms: 60
memory_kb: 34888
final_rank: 8

code_snippet: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

class Edge{
public:
    int from, to, rev;
    Int cost, lim;
    Edge(int from, int to, Int cost, int lim = -1, Int rev = -1):
        from(from),to(to),cost(cost),lim(lim),rev(rev){}
};


class Graph{
public:
    int n;
    int m;
    vector<vector<Edge>> edge;
    Graph(int n = 0):n(n),m(0){
        edge = vector<vector<Edge>>(n);
    }
    void add_edge(int from, int to, int cost = 1, int lim = -1)
        {
            if(lim == -1){
                edge[from].push_back(Edge(from, to, cost));
                return;
            }
            edge[from].push_back(Edge(from, to, cost, lim, edge[to].size()));
            edge[to].push_back(Edge(to, from, -cost, 0, edge[from].size() - 1));
        }
};



vector<Int> Dijkstra(Graph &g, int s){
    priority_queue<P, vector<P>, greater<P> > pq;
    vector<Int> dist(g.n, INF);
    pq.push(P(0, s));
    dist[s] = 0;

    while(!pq.empty()){
        P tmp = pq.top();pq.pop();
        int from = tmp.second;
        if(tmp.first > dist[from])continue;
        for(auto e: g.edge[from]){
            if(dist[e.to] <= dist[from] + e.cost)continue;
            dist[e.to] = dist[from] + e.cost;
            pq.push(P(dist[e.to], e.to));
        }
    }
    return dist;
}

Int n, v, u;
vector<Int> nums;
int main(){
    cin >> n;
    Graph g(2200000);
    for(int i = 0;i < n;i++){
        cin >> u >> v;
        if(u > v)swap(u, v);
        g.add_edge(v, u, v-u-1);
        g.add_edge(v + 1050000, u + 1050000, v-u-1);
        g.add_edge(u + 1050000, u, u+1050000-v-1);
    }
    for(int i = 1;i < 2200000;i++){
        g.add_edge(i, i-1, 1);
    }
    Int need = LINF;
    auto dist = Dijkstra(g, 2160000);
    for(int i = 2100000;i - 1050000 >= 0;i--){
        int j = i - 1050000;
        need = min(need, i - j + dist[i] - dist[j]);
    }
    cout << (need + 2) / 2 << endl;
    return 0;
}
accuracy: 0.3829787234042553
time_ms: 710
memory_kb: 210128
final_rank: 10

code_snippet: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

class Edge{
public:
    int from, to, rev;
    Int cost, lim;
    Edge(int from, int to, Int cost, int lim = -1, Int rev = -1):
        from(from),to(to),cost(cost),lim(lim),rev(rev){}
};


class Graph{
public:
    int n;
    int m;
    vector<vector<Edge>> edge;
    Graph(int n = 0):n(n),m(0){
        edge = vector<vector<Edge>>(n);
    }
    void add_edge(int from, int to, int cost = 1, int lim = -1)
        {
            if(lim == -1){
                edge[from].push_back(Edge(from, to, cost));
                return;
            }
            edge[from].push_back(Edge(from, to, cost, lim, edge[to].size()));
            edge[to].push_back(Edge(to, from, -cost, 0, edge[from].size() - 1));
        }
};



vector<Int> Dijkstra(Graph &g, int s){
    priority_queue<P, vector<P>, greater<P> > pq;
    vector<Int> dist(g.n, INF);
    pq.push(P(0, s));
    dist[s] = 0;

    while(!pq.empty()){
        P tmp = pq.top();pq.pop();
        int from = tmp.second;
        if(tmp.first > dist[from])continue;
        for(auto e: g.edge[from]){
            if(dist[e.to] <= dist[from] + e.cost)continue;
            dist[e.to] = dist[from] + e.cost;
            pq.push(P(dist[e.to], e.to));
        }
    }
    return dist;
}

Int n;
Int u[1080000], v[1080000];
vector<Int> nums;
int main(){
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> u[i] >> v[i];
        nums.push_back(u[i]);
        nums.push_back(v[i]);
    }
    sort(nums.begin(), nums.end());
    nums.erase(unique(nums.begin(), nums.end()), nums.end());
    Graph g(nums.size());
    for(int i = 0;i < n;i++){
        u[i] = lower_bound(nums.begin(), nums.end(), u[i]) - nums.begin();
        v[i] = lower_bound(nums.begin(), nums.end(), v[i]) - nums.begin();
        if(u[i] > v[i])swap(u[i], v[i]);
        g.add_edge(v[i], u[i]);
    }
    for(int i = 1;i < nums.size();i++){
        g.add_edge(i, i-1);
    }
    auto dist = Dijkstra(g, nums.size() - 1);
    cout << (dist[0] + 1) / 2 << endl;
    return 0;
}
accuracy: 0.02127659574468085
time_ms: 120
memory_kb: 34052
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;

const int SIZE=1e6;
const int LOGN=22;
int main(){
    int N;
    cin>>N;
    vector<int> a(N),b(N);
    for(int i=0;i<N;i++){
        cin>>a[i]>>b[i];
    }
    vector<vector<int>> g(SIZE);
    for(int i=0;i<N;i++){
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }
    // cerr<<"#input finished"<<endl;
    vector<int> val(SIZE);
    auto isInLR=[&](int l,int r,int x){
        if(l<r){
            return l<=x && x<r;
        }
        else{
            return l<=x || x<r;
        }
    };

    vector<int> cnt(SIZE,0);
    for(auto to:g[0]) cnt[to]++;

    auto isValid=[&](int r){
        return cnt[(r+SIZE-1)%SIZE]==0;
    };

    // cerr<<"#precalucalating"<<endl;
    int r=1;
    for(int l=0;l<SIZE;l++){
        // calc val[l]
        while(isValid(r)){
            for(auto to:g[r]){
                // if(!isInLR(l,r,to)){ iranai
                cnt[to]++;
            }
            r++;
            r%=SIZE;
        }
        val[l]=(l<r ? r-1-l : r+SIZE-l-1);
        // pop l
        for(auto to:g[l]){
            cnt[to]--;
        }
    }

    
    // cerr<<"#doubling"<<endl;
    vector<vector<int>> dp(LOGN,vector<int>(SIZE));
    dp[0]=val;

    for(int i=0;i+1<LOGN;i++){
        for(int j=0;j<SIZE;j++){
            dp[i+1][j]=min(dp[i][(j+dp[i][j])%SIZE]+dp[i][j],SIZE*2);
        }
    }
    // cerr<<dp[1][dp[1][0]]<<endl;
    // cerr<<"#solving"<<endl;
    // cerr<<dp[19][0]<<endl;
    // cerr<<dp[0][666666]<<endl;
    // cerr<<dp[1][0]<<" "<<dp[0][0]<<" "<<dp[0][dp[0][0]]+dp[0][0]<<endl;
    // cerr<<dp[2][0]<<" "<<dp[1][0]<<" "<<dp[1][(dp[1][0])%SIZE]+dp[1][0]<<endl;
    int res=SIZE;
    for(int i=0;i<SIZE;i++){
        int tar=SIZE;
        int sc=0;
        int from=i;
        for(int j=LOGN-1;j>=0;j--){
            if(tar>dp[j][from]){
                sc+=(1<<j);
                tar-=dp[j][from];
                from=(from+dp[j][from])%SIZE;
            }
        }
        for(int j=0;j<LOGN;j++){
            if(dp[j][from]>=tar){
                sc+=(1<<j);
                break;
            }
        }
        res=min(res,sc);
    }

    cout<<(res/2+res%2)<<endl;
    return 0;
}
accuracy: 1
time_ms: 280
memory_kb: 135816
final_rank: 3

code_snippet: #include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;
#define int long long

signed main(){
    int K=1000000;
    int N;
    cin >> N;
    vector<pair<int, int> > A(N);
    vector<pair<int, int> > B(N);
    for(int i=0;i<N;i++){
        cin >> A[i].second >> A[i].first;
    }
    
    for(int i=0;i<N;i++){
        A.push_back(A[i]);
        A.back().second+=K;
        swap(A.back().first, A.back().second);
    }
    
    
    
    
     N*=2;
     for(int i=0;i<N;i++){
         A.push_back(A[i]);
         A.back().first+=K;
         A.back().second+=K;
     }
    sort(A.begin(),A.end());
    for(int i=0;i<2*N;i++){
        swap(A[i].first, A[i].second);
    }
    const int sz = 22;
    vector<vector<int> > ne(2 * N, vector<int>(sz));
    vector<pair<int,int> > X(3 * K + 1, make_pair(5 * K ,  2 * N));
    int cur = 3 * K;
    for(int i=2 * N - 1;i  >= 0;i--){
        while(A[i].second < cur){
            cur--;
            X[cur] = min(X[cur], X[cur + 1]);
        }
        X[A[i].first] = min(X[A[i].first], make_pair(A[i].second, i));
        ne[i][0] = X[cur].second;
        
    }
    
    for(int j=1;j<sz;j++){
        for(int i=0;i<2*N;i++){
            int t = ne[i][j-1];
            if(t < 2 * N){
                ne[i][j] = ne[t][j-1];
            }else{
                ne[i][j] = 2 * N;
            }
        }
    }
    
    
    // for(int i=0;i<2*N;i++){
    //     cerr << i << " " << A[i].first << " " << A[i].second <<" " << ne[i][0] << endl;
    // }
    
    
    int res = 1000000000;
    
    for(int i=0;i<N/2;i++){
        int cur = i;
        int tmp = 1;
        for(int j=sz-1;j>=0;j--){
            
            if(ne[cur][j] < 2 * N && A[ne[cur][j]].second < A[i].second + K){
                tmp += (1 << j);
                cur = ne[cur][j];
            }
            
        }
        res = min(res, (tmp + 1) / 2);
    }
    
    
    cout << res << endl;
    return 0;
}
accuracy: 1
time_ms: 620
memory_kb: 234076
final_rank: 4

code_snippet: #include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;
#define int long long

signed main(){
    int K=1000000;
    int N;
    cin >> N;
    vector<pair<int, int> > A(N);
    vector<pair<int, int> > B(N);
    for(int i=0;i<N;i++){
        cin >> A[i].second >> A[i].first;
    }
    
    for(int i=0;i<N;i++){
        A.push_back(A[i]);
        A.back().second+=K;
        swap(A.back().first, A.back().second);
    }
    
    
    
    
     N*=2;
     for(int i=0;i<N;i++){
         A.push_back(A[i]);
         A.back().first+=K;
         A.back().second+=K;
     }
    sort(A.begin(),A.end());
    for(int i=0;i<2*N;i++){
        swap(A[i].first, A[i].second);
    }
    const int sz = 22;
    vector<vector<int> > ne(2 * N, vector<int>(sz));
    vector<pair<int,int> > X(3 * K + 1, make_pair(5 * K ,  2 * N));
    int cur = 3 * K;
    for(int i=2 * N - 1;i  >= 0;i--){
        while(A[i].second < cur){
            cur--;
            X[cur] = min(X[cur], X[cur + 1]);
        }
        X[A[i].first] = min(X[A[i].first], make_pair(A[i].second, i));
        ne[i][0] = X[cur].second;
        
    }
    
    for(int j=1;j<sz;j++){
        for(int i=0;i<2*N;i++){
            int t = ne[i][j-1];
            if(t < 2 * N){
                ne[i][j] = ne[t][j-1];
            }else{
                ne[i][j] = 2 * N;
            }
        }
    }
    
    
    // for(int i=0;i<2*N;i++){
    //     cerr << i << " " << A[i].first << " " << A[i].second <<" " << ne[i][0] << endl;
    // }
    
    
    int res = 1000000000;
    
    for(int i=0;i<N/2;i++){
        int cur = i;
        int tmp = 1;
        for(int j=sz-1;j>=0;j--){
            
            if(ne[cur][j] < 2 * N && A[ne[cur][j]].first < A[i].first + K){
                tmp += (1 << j);
                cur = ne[cur][j];
            }
            
        }
        res = min(res, (tmp + 1) / 2);
    }
    
    
    cout << res << endl;
    return 0;
}
accuracy: 0.14893617021276595
time_ms: 620
memory_kb: 234068
final_rank: 19

code_snippet: #include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;
#define int long long

signed main(){
    int K=1000000;
    int N;
    cin >> N;
    vector<pair<int, int> > A(N);
    vector<pair<int, int> > B(N);
    for(int i=0;i<N;i++){
        cin >> A[i].second >> A[i].first;
    }
    
    for(int i=0;i<N;i++){
        A.push_back(A[i]);
        A.back().second+=K;
        swap(A.back().first, A.back().second);
    }
    
    
    sort(A.begin(),A.end());
    
     N*=2;
     for(int i=0;i<N;i++){
         A.push_back(A[i]);
         A.back().first+=K;
         A.back().second+=K;
     }
    for(int i=0;i<2*N;i++){
        swap(A[i].first, A[i].second);
    }
    const int sz = 22;
    vector<vector<int> > ne(2 * N, vector<int>(sz));
    vector<pair<int,int> > X(3 * K + 1, make_pair(5 * K ,  2 * N));
    int cur = 3 * K;
    for(int i=2 * N - 1;i  >= 0;i--){
        while(A[i].second < cur){
            cur--;
            X[cur] = min(X[cur], X[cur + 1]);
        }
        X[A[i].first] = min(X[A[i].first], make_pair(A[i].second, i));
        ne[i][0] = X[cur].second;
        
    }
    
    for(int j=1;j<sz;j++){
        for(int i=0;i<2*N;i++){
            int t = ne[i][j-1];
            if(t < 2 * N){
                ne[i][j] = ne[t][j-1];
            }else{
                ne[i][j] = 2 * N;
            }
        }
    }
    
    
    // for(int i=0;i<2*N;i++){
    //     cerr << i << " " << A[i].first << " " << A[i].second <<" " << ne[i][0] << endl;
    // }
    
    
    int res = 1000000000;
    
    for(int i=0;i<N/2;i++){
        int cur = i;
        int tmp = 1;
        for(int j=sz-1;j>=0;j--){
            
            if(ne[cur][j] < 2 * N && A[ne[cur][j]].first < A[i].first + K){
                tmp += (1 << j);
                cur = ne[cur][j];
            }
            
        }
        res = min(res, (tmp + 1) / 2);
    }
    
    
    cout << res << endl;
    return 0;
}
accuracy: 0.14893617021276595
time_ms: 580
memory_kb: 234116
final_rank: 16

code_snippet: #include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;
#define int long long

signed main(){
    int K=1000000;
    int N;
    cin >> N;
    vector<pair<int, int> > A(N);
    vector<pair<int, int> > B(N);
    for(int i=0;i<N;i++){
        cin >> A[i].second >> A[i].first;
    }
    
    for(int i=0;i<N;i++){
        A.push_back(A[i]);
        A.back().second+=K;
        swap(A.back().first, A.back().second);
    }
    
    
    sort(A.begin(),A.end());
    
     N*=2;
     for(int i=0;i<N;i++){
         A.push_back(A[i]);
         A.back().first+=K;
         A.back().second+=K;
     }
    for(int i=0;i<2*N;i++){
        swap(A[i].first, A[i].second);
    }
    const int sz = 22;
    vector<vector<int> > ne(2 * N, vector<int>(sz));
    vector<pair<int,int> > X(3 * K + 1, make_pair(5 * K ,  2 * N));
    int cur = 3 * K;
    for(int i=2 * N - 1;i  >= 0;i--){
        while(A[i].second < cur){
            cur--;
            X[cur] = min(X[cur], X[cur + 1]);
        }
        X[A[i].first] = min(X[A[i].first], make_pair(A[i].second, i));
        ne[i][0] = X[cur].second;
        
    }
    
    for(int j=1;j<sz;j++){
        for(int i=0;i<2*N;i++){
            int t = ne[i][j-1];
            if(t < 2 * N){
                ne[i][j] = ne[t][j-1];
            }else{
                ne[i][j] = 2 * N;
            }
        }
    }
    
    
    // for(int i=0;i<2*N;i++){
    //     cerr << i << " " << A[i].first << " " << A[i].second <<" " << ne[i][0] << endl;
    // }
    
    
    int res = 1000000000;
    
    for(int i=0;i<N;i++){
        int cur = i;
        int tmp = 1;
        for(int j=sz-1;j>=0;j--){
            
            if(ne[cur][j] < 2 * N && A[ne[cur][j]].first < A[i].first + K){
                tmp += (1 << j);
                cur = ne[cur][j];
            }
            
        }
        res = min(res, (tmp + 1) / 2);
    }
    
    
    cout << res << endl;
    return 0;
}
accuracy: 0.14893617021276595
time_ms: 590
memory_kb: 234068
final_rank: 17

code_snippet: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;

typedef pair<int, int> P;

struct SegT {
private:
	int sz; vector<int> node;
	const int init_c = mod;
public:
	SegT(int n) {
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
	}
	int f(int a, int b) {
		return min(a, b);
	}
	void update(int k, int a) {
		k += sz - 1;
		node[k] = min(node[k],a);
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	int query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = sz;
		if (r <= a || b <= l)return init_c;
		else if (a <= l && r <= b)return node[k];
		else {
			int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
};

int sz = 1000000;
int nex[1 << 21][20];
void solve() {
	int n;
	cin >> n;
	vector<P> v(n);
	rep(i, n) {
		cin >> v[i].first >> v[i].second;
	}
	if (n == 1) {
		cout << 1 << endl; return;
	}
	sort(v.begin(), v.end());
	rep(i, n) {
		v.push_back({ v[i].second,v[i].first + sz });
	}
	sort(v.begin(), v.end());
	rep(i, 2 * n) {
		v.push_back({ v[i].first + sz, v[i].second + sz });
	}
	sort(v.begin(), v.end());
	SegT st(1 << 21);
	rep(i, 4 * n) {
		st.update(v[i].first, v[i].second);
	}

	int ma = 1;
	rep(i, 2*sz) {
		nex[i][0] = st.query(i, (1 << 21));
	}
	rep(j, 19) {
		rep(i, 2*sz) {
			if (nex[i][j] >=2*sz)nex[i][j + 1] = 2*sz;
			else {
				nex[i][j + 1] = nex[nex[i][j]][j];
			}
		}
	}
	rep(i, sz) {
		int s = 0;
		int cur = i;
		for (int j = 19; j >= 0; j--) {
			if (nex[cur][j] > i + sz)continue;
			s += (1 << j);
			cur = nex[cur][j];
		}
		ma = max(ma, s);
	}
	int ans = (1 + ma) / 2;
	ans = min(ans, (n + 1) / 2);
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	//stop
	return 0;
}
accuracy: 0.7659574468085106
time_ms: 820
memory_kb: 181656
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, N) for (int i = 0; i < (N); ++i)

signed main() {
    int n; cin >> n;
    vector<pair<int, int>> st;
    for(int i = 1; i <= n; ++i) {
        int a, b; cin >> a >> b;
        st.emplace_back(a, -i);
        st.emplace_back(b, i);
    }
    sort(st.begin(), st.end());
    int nnnn = st.size();
    int offset = 0;
    while(true) {
        if(st[nnnn - 1].second == -st[nnnn - 2].second) {
            // cerr << "ok" << endl;
            reverse(st.begin(), st.end());
            st.emplace_back(st[0]);
            reverse(st.begin(), st.end());
            st.pop_back();
            if (st[0].second > 0) {
                st[0].second *= -1;
                st.back().second *= -1;
            }
            // offset = 1;
        } else {
            break;
        }
    }
    // for(auto p : st) {
    //     cout << p.first << " " << p.second << endl;
    // }
    // set<int> sst;
    int ans = 0;
    bool reset = true; 
    for(int i = 0; i < st.size() - offset; ++i) {
        int who, num;
        tie(who, num) = st[i];
        // cerr << i << ' ' << who << ' ' << num << endl;
        // new
        if(num < 0) {
            // cerr << who << " " << num << endl;
            num = -num;
            // sst.insert(num);
            if(reset) {
                reset = false;
                ans++;
                while(true) {
                    ++i;
                    if(i == st.size() - offset) break;
                    int wwho, nnum;
                    tie(wwho, nnum) = st[i];
                    if(nnum > 0) {
                        i -= 1;
                        break;
                    } 
                    if(wwho != who) {
                        i -= 1;
                        break;
                    }
                    // sst.insert(-nnum);
                }
            }
            // sst.insert(num);
        } else {
            reset = true;
        }
    }
    cout << ans << endl;
}
accuracy: 0.14893617021276595
time_ms: 90
memory_kb: 6956
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, N) for (int i = 0; i < (N); ++i)

signed main() {
    int n; cin >> n;
    vector<pair<int, int>> st;
    for(int i = 1; i <= n; ++i) {
        int a, b; cin >> a >> b;
        st.emplace_back(a, -i);
        st.emplace_back(b, i);
    }
    sort(st.begin(), st.end());
    int nnnn = st.size();
    int offset = 0;
    if(st[nnnn - 1].second == -st[nnnn - 2].second) {
        // cerr << "ok" << endl;
        reverse(st.begin(), st.end());
        st.emplace_back(st[0]);
        reverse(st.begin(), st.end());
        st.pop_back();
        if (st[0].second > 0) {
            st[0].second *= -1;
            st.back().second *= -1;
        }
        // offset = 1;
    }
    // for(auto p : st) {
    //     cout << p.first << " " << p.second << endl;
    // }
    // set<int> sst;
    int ans = 0;
    bool reset = true; 
    for(int i = 0; i < st.size() - offset; ++i) {
        int who, num;
        tie(who, num) = st[i];
        // cerr << i << ' ' << who << ' ' << num << endl;
        // new
        if(num < 0) {
            // cerr << who << " " << num << endl;
            num = -num;
            // sst.insert(num);
            if(reset) {
                reset = false;
                ans++;
                while(true) {
                    ++i;
                    if(i == st.size() - offset) break;
                    int wwho, nnum;
                    tie(wwho, nnum) = st[i];
                    if(nnum > 0) {
                        i -= 1;
                        break;
                    } 
                    if(wwho != who) {
                        i -= 1;
                        break;
                    }
                    // sst.insert(-nnum);
                }
            }
            // sst.insert(num);
        } else {
            reset = true;
        }
    }
    cout << ans << endl;
}
accuracy: 0.14893617021276595
time_ms: 90
memory_kb: 6956
final_rank: 11

code_snippet: #include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;
#define int long long

signed main(){
    int K=1000000;
    int N;
    cin >> N;
    vector<pair<int, int> > A(N);
    vector<pair<int, int> > B(N);
    for(int i=0;i<N;i++){
        cin >> A[i].second >> A[i].first;
    }
    
    for(int i=0;i<N;i++){
        A.push_back(A[i]);
        A.back().second+=K;
        swap(A.back().first, A.back().second);
    }
    
    
    sort(A.begin(),A.end());
    
     N*=2;
     for(int i=0;i<N;i++){
         A.push_back(A[i]);
         A.back().first+=K;
         A.back().second+=K;
     }
    for(int i=0;i<2*N;i++){
        swap(A[i].first, A[i].second);
    }
    const int sz = 22;
    vector<vector<int> > ne(2 * N, vector<int>(sz));
    vector<pair<int,int> > X(3 * K + 1, make_pair(5 * K ,  2 * N));
    int cur = 3 * K;
    for(int i=2 * N - 1;i  >= 0;i--){
        while(A[i].second < cur){
            cur--;
            X[cur] = min(X[cur], X[cur + 1]);
        }
        X[A[i].first] = min(X[A[i].first], make_pair(A[i].second, i));
        ne[i][0] = X[cur].second;
        
    }
    
    for(int j=1;j<sz;j++){
        for(int i=0;i<2*N;i++){
            int t = ne[i][j-1];
            if(t < 2 * N){
                ne[i][j] = ne[t][j-1];
            }else{
                ne[i][j] = 2 * N;
            }
        }
    }
    
    
    // for(int i=0;i<2*N;i++){
    //     cerr << i << " " << A[i].first << " " << A[i].second <<" " << ne[i][0] << endl;
    // }
    
    
    int res = 10000000;
    
    for(int i=0;i<N;i++){
        int cur = i;
        int tmp = 1;
        for(int j=sz-1;j>=0;j--){
            
            if(ne[cur][j] < 2 * N && A[ne[cur][j]].second <= A[i].first + K){
                tmp += (1 << j);
                cur = ne[cur][j];
            }
            
        }
        res = min(res, (tmp + 1) / 2);
    }
    
    
    cout << res << endl;
    return 0;
}
accuracy: 0.14893617021276595
time_ms: 600
memory_kb: 234048
final_rank: 18

code_snippet: //
// Created by maze on 2019/09/15.
//

#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int64)1e9
#define lp(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a); i < (b); i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int32_t;
using int64 = int64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

int main(void) {
    int n;
    cin>>n;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    lp(i,n){
        int a,b;
        cin>>a>>b;
        q.push({a,0});
        q.push({b,-1});
    }
    int ans=0;
    int mode=0;
    set<int> s;
    lp(i,n*2){
        int nm=q.top().second;
        int n=q.top().first;
        q.pop();
        if(mode==0){
            if(nm==0){
                mode=1;
                ans++;
                s.clear();
            }
            else continue;
        }
        else{
            if(nm==-1){
                if(s.find(n)!=s.end()){
                    mode=0;
                }
                if(ans==1)mode=0;
            }
            else{
                s.insert(n);
            }
        }
    }
    cout<<ans<<endl;
}
accuracy: 0.14893617021276595
time_ms: 170
memory_kb: 15264
final_rank: 15

code_snippet: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;

typedef pair<int, int> P;

struct SegT {
private:
	int sz; vector<int> node;
	const int init_c = mod;
public:
	SegT(int n) {
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
	}
	int f(int a, int b) {
		return min(a, b);
	}
	void update(int k, int a) {
		k += sz - 1;
		node[k] = min(node[k],a);
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	int query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = sz;
		if (r <= a || b <= l)return init_c;
		else if (a <= l && r <= b)return node[k];
		else {
			int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
};

int sz = 1000000;
int nex[1 << 21][20];
void solve() {
	int n;
	cin >> n;
	vector<P> v(n);
	rep(i, n) {
		cin >> v[i].first >> v[i].second;
	}
	if (n == 1) {
		cout << 1 << endl; return;
	}
	sort(v.begin(), v.end());
	rep(i, n) {
		v.push_back({ v[i].second,v[i].first + sz });
	}
	sort(v.begin(), v.end());
	rep(i, 2 * n) {
		v.push_back({ v[i].first + sz, v[i].second + sz });
	}
	sort(v.begin(), v.end());
	SegT st(1 << 21);
	rep(i, 4 * n) {
		st.update(v[i].first, v[i].second);
	}

	int ma = 1;
	rep(i, 2*sz) {
		nex[i][0] = st.query(i, (1 << 21));
	}
	rep(j, 19) {
		rep(i, 2*sz) {
			if (nex[i][j] >=2*sz)nex[i][j + 1] = mod;
			else {
				nex[i][j + 1] = nex[nex[i][j]][j];
			}
		}
	}
	rep(i, sz) {
		int s = 0;
		int cur = i;
		for (int j = 19; j >= 0; j--) {
			if (nex[cur][j] > i + sz)continue;
			s += (1 << j);
			cur = nex[cur][j];
		}
		ma = max(ma, s);
	}
	cout << (1 + ma) / 2 << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	//stop
	return 0;
}
accuracy: 0.7659574468085106
time_ms: 830
memory_kb: 181668
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i, a, b) for(int i = (int)(a);i < (int)b; ++i)
#define ll long long

constexpr int INF = 1000000007;
void solve() {
    int N;
    cin >> N;
    pair<int, int> hate[N];
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        hate[i] = make_pair(a, b);
    }
    sort(hate, hate + N);
    int u = 0, r = INF, ans = 1;
    int minWall = INF, maxWall = -1;
    rep(i, 1000001) { // iは現在見ている位置を指す
        if (r == i) {
            ++ ans;
            minWall = min(minWall, i);
            maxWall = max(maxWall, i);
            r = INF;
            //cout << "Wall:" << i - 1 << ".5" << endl;
        }
        while (u < N && hate[u].first == i) { // 少なくともrまでに壁がいる
            r = min(r, hate[u].second);
            ++ u;
        }
    }
    rep(i, N) { // この貪欲だと逆側から繋がるケースがある場合があるので、それの判定
        if (hate[i].first < minWall && maxWall <= hate[i].second) {
            ++ ans;
            //cout << "Wall: 999999.5" << endl;
            break;
        }
    }
    cout << ans / 2 << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);



    solve();

    return 0;
}
accuracy: 0.6170212765957447
time_ms: 30
memory_kb: 4732
final_rank: 7