1打卡题
递增三元组
package daka;
import java.util.*;
/*递增三元组
* 三个数组
* 三元组(i,j,k) 满足: 1<=i,j,k <=n;
* Ai<bj<ck;
* 111
* 222
* 333
* 27(9 * 3);
*/
public class dezeng {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int [] a = new int [n+1];
int [] b = new int [n+1];
int [] c = new int [n+1];
for(int i=1;i<=n;i++) {
int num = sc.nextInt();
num = a[i];
}
for(int i=1;i<=n;i++) {
int num = sc.nextInt();
num = b[i];
}
for(int i=1;i<=n;i++) {
int num = sc.nextInt();
num = c[i];
}
Arrays.sort(a);Arrays.sort(b);Arrays.sort(c);
long res = 0; //注意long类型。不用的话过不了
//指针在a和c数组中移动,同时固定b数组的指针遍历
//indexa:数组a中小于b的最后一个下标
//indexb:数组c中大于b的第一个下标
//a一定小于b且不等于b,c一定大于b,但可以等于b
for(int i =1, indexa = 1,indexc = 1;i<=n;i++) {
//indexa < i <= indexc
while(indexa<=n && a[indexa]< b[i]) {
indexa++;
}
while(indexc <=n && c[indexc]<= b[i]) {
indexc++;
}
res += (long)(indexa -1) * (n-indexc -1);
}
System.out.println(res);
}
}
3.你们
4.