【BZOJ】【P1510】【POI2006】【Kra-The Disks】【题解】【前缀min+二分】

传送门:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1510

没错,你没有看错,我又在刷水题了

Code:

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=3e5+5;
int mn[maxn];
int ans,n,m,x,p,res;
int getint(){
	int res=0;char c=getchar();
	while(!isdigit(c))c=getchar();
	while(isdigit(c))res=res*10+c-'0',c=getchar();
	return res;
}
int main(){
	scanf("%d%d",&n,&m);ans=n+1;mn[0]=1e9+10;
	for(int i=1;i<=n;i++)x=getint(),mn[i]=min(mn[i-1],x);
	for(int i=1;i<=m;i++){
		x=getint();
		p=upper_bound(mn+1,mn+ans,x,greater<int>())-mn-1;
		ans=p;
	}cout<<max(0,ans)<<endl;
	return 0;
}


你可能感兴趣的:(bzoj)