//想问这个是上机还是笔试手写校招的题目呀。第四题。
class Solution{
public void me(int[] a,int[]b)
{
Stack<Integer>stack=new Stack<>();
int len=a.length;
int maxa=Integer.MIN_VALUE;
int minb=Integer.MAX_VALUE;
for(int i=0;i<len;i++)
{
if(a[i]>maxa)maxa=a[i];
if(b[i]<minb)minb=b[i];
if(maxa<minb) {stack.push(i);continue;}
if(a[i]<b[i]) {
maxa=a[i];
minb=b[i];
stack.push(-1);
stack.push(i);
//System.out.print(stack.peek()+" ");
continue;
}
else {
maxa=Integer.MIN_VALUE;
minb=Integer.MAX_VALUE;
stack.push(-1);
//压栈完毕
}
}
int count=1;
int sum=0;
while(!stack.isEmpty())
{
int pre=stack.pop();//判定连续
if(!stack.isEmpty())
{
if(stack.peek()!=-1)
{
count++;continue;
}
else {
stack.pop();
sum+=count*(count+1)/2;
count=1;continue;
}
}
sum+=count*(count+1)/2;
}
System.out.print(sum);
}
}