JAVA 双数组实现+快排
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for(int i=0;i< n;i++){
a[i] = sc.nextInt();
b[i] = sc.nextInt();
}
quickSort(a,b,0,n-1);
int count = 0;
int max = Integer.MIN_VALUE;
for(int i=0 ; i<n ; i++ ){
if(max < a[i]){
count++;
}
if(b[i] >= max){
max = b[i];
}
}
System.out.println(count);
}
static void quickSort(int[] a,int[] b,int l,int r){
if(l >= r) return;
int i = l-1;
int j = r+1;
int mid = l+r >>1;
int x = a[mid];
while(i <j){
do{i++;}while(a[i] < x);
do{j--;}while(a[j] > x);
if(i<j){
int temA = a[i];
a[i] = a[j];
a[j] = temA;
int temB = b[i];
b[i] = b[j];
b[j] = temB;
}
}
quickSort(a,b,l,j);
quickSort(a,b,j+1,r);
}
}