蓝桥杯冲刺打卡31天day17

1、ASC

import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        scan.close();
    }
}

2、递增三元组

题目描述

给定三个整数数组

A=[A1​,A2​,⋯AN​],

B=[B1​,B2​,⋯BN​],

C=[C1​,C2​,⋯CN​],

请你统计有多少个三元组 (i,j,k) 满足:

  1. 1≤i,j,k≤N;

  2. Ai​<Bj​<Ck​。

输入描述

第一行包含一个整数 N。

第二行包含 N 个整数 A1​,A2​,⋯AN​。

第三行包含 N 个整数 B1​,B2​,⋯BN​。

第四行包含 N 个整数 C1​,C2​,⋯CN​。

其中,1≤N≤105,0≤Ai,Bi,Ci≤105。

输出描述

输出一个整数表示答案。

输入输出样例

示例

输入

3
1 1 1
2 2 2
3 3 3

输出

27

运行限制

  • 最大运行时间:2s
  • 最大运行内存: 256M
import java.util.*;
import java.io.*;
public class 递增三元组 {
	 static int N = (int) 1e5+10;
	 static int []a = new int[N];
	 static int []b = new int[N];
	 static int []c = new int[N];
     static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
     static PrintWriter out = new PrintWriter(new BufferedWriter (new OutputStreamWriter(System.out)));
	public static void main(String[] args) throws IOException {
     String[] s = in.readLine().split(" ");
     int n = Integer.parseInt(s[0]);
     s= in.readLine().split(" ");
     for(int i=0;i<n;i++) {
    	 a[i]=Integer.parseInt(s[i]);
     }
     s=in.readLine().split(" ");
     for(int i=0;i<n;i++) {
    	 b[i]=Integer.parseInt(s[i]);
     }
     s=in.readLine().split(" ");
     for(int i=0;i<n;i++) {
    	 c[i]=Integer.parseInt(s[i]);
     }
     Arrays.sort(a,0,n);
     Arrays.sort(b,0,n);
     Arrays.sort(c,0,n);
     long res = 0L;
     for(int i =0;i<n;i++) {//每次以中间数组B为中心,从A数组找到比B数组小的(找到最后一个满足的),从C数组中找到比B数组大的(找到第一个满足的),从而进行匹配
    	int l = 0;
    	int r = n-1;
    	while(l<r) {
    		int mid=l+r+1>>1;//目标在右边方向
    		if(a[mid]<b[i]) {
    			l = mid;
    		}else {
    		    r = mid-1;
    		}
    	}
    	int BA = l;
    	 l = 0;
    	 r = n-1;
        while(l<r) {
        	int mid = l+r>>1;//目标在左边方向
        	if(c[mid]>b[i]) {
        		r = mid;
        	}else {
        		l = mid+1;
        	}
        }
        int CB = l;
       // res+=(long)(BA+1)*(n-CB);
        if(a[BA]<b[i]&&c[CB]>b[i]) {
       	  res+=(long)(BA+1)*(n-CB);
         }
    	 
     }
     System.out.println(res);
	}

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值