https://ac.nowcoder.com/acm/contest/881/A
题意就很难懂!!
/*
题意:给两个数组且元素不重复,找最大P值(p的含义为在下标1~p中的任意l,r区间内的某下标的一对值都是这个l,r区间的最小值)
题解:两个单调递减栈 找当两栈元素个数不同时break掉就好了。关键就是break掉(结合题意)
理解样例:30 10 50 20 40 3 1 5 2 4
50 20 40 30 10 5 2 4 3 1
答案是 4
在下标为4时,两栈内元素个数不同
*/
/*
题意:给两个数组且元素不重复,找最大P值(p的含义为在下标1~p中的任意l,r区间内的某下标的一对值都是这个l,r区间的最小值)
题解:两个单调递减栈 找当两栈元素个数不同时break掉就好了。
理解样例:30 10 50 20 40 3 1 5 2 4
50 20 40 30 10 5 2 4 3 1
答案是 4
在下标为4时,两栈内元素个数不同
*/
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<stack>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=1000000;
stack<int>na,nb;
int a[maxn];
int b[maxn];
int main(){
int n;
while(cin>>n){
while(!na.empty()) na.pop();
while(!nb.empty()) nb.pop();
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
cin>>b[i];
na.push(a[0]);
nb.push(b[0]);
int i=0;
for(i=1;i<n;i++){
while(!na.empty()&&a[i]<na.top()) na.pop();
na.push(a[i]);
while(!nb.empty()&&b[i]<nb.top()) nb.pop();
nb.push(b[i]);
if(na.size()!=nb.size()) break;
}
cout<<i<<endl;
}
return 0;
}
/*
2
1 2
2 1
3
2 1 3
3 1 2
5
3 1 5 2 4
5 2 4 3 1
*/