描述
给定一个长度为N的数组A=[A1, A2, ... AN],已知其中每个元素Ai的值都只可能是1, 2或者3。
请求出有多少下标三元组(i, j, k)满足1 ≤ i < j < k ≤ N且Ai < Aj < Ak。
输入
第一行包含一个整数N
第二行包含N个整数A1, A2, ... AN。(1 ≤ Ai ≤ 3)
对于30%的数据,1 ≤ N ≤ 100
对于80%的数据,1 ≤ N ≤ 1000
对于100%的数据,1 ≤ N ≤ 100000
输出
一个整数表示答案
样例输入
6 1 3 2 1 2 3
样例输出
3
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
while(sc.hasNextInt())
{
int n=sc.nextInt();
long x ,s1=0,s2=0,s3=0; //定义为int通不过,解法很妙,所以没必要建数组
for(int i=0;i<n;i++)
{
x=sc.nextInt();
if(x==1)
{
s1++;
}
if(x==2)
{
s2+=s1;
}
if(x==3)
{
s3+=s2;
}
}
System.out.println(s3);
}
}
}