Kra-The Disks bzoj-1510 POI-2006
题目大意:题目链接。
注释:略。
想法:不难发现其实只有前缀最小值是有效的。
进而我们把盘子一个一个往里放,弄一个自底向上的指针往上蹦即可。
时间复杂度$O(n)$。
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 300010
using namespace std;
int a[N],bfr[N];
int main()
{
// freopen("gift.in","r",stdin);
// freopen("gift.out","w",stdout);
bfr[0]=1000000000;
int n,m; cin >> n >> m ; for(int i=1;i<=n;i++) scanf("%d",&a[i]),bfr[i]=min(bfr[i-1],a[i]);
int k=n; for(int i=1;i<=m;i++)
{
int x; cin >> x ;
if(bfr[1]<x) puts("0"),exit(0);
while(bfr[k]<x) k--;
k--;
}
printf("%d\n",k+1);
// fclose(stdin); fclose(stdout);
return 0;
}
小结:水题。