#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#define N 20000
using namespace std;
int Max(int x,int y){if(x<y) return y;return x;}
int p[N];
struct seg
{
int s,e;
seg(int _s=0,int _e=0){s=_s,e=_e;}
}a[N];
int k[N],top,top2,m[N];
int M(int s,int e)
{
if(s==e) return p[e];
int mid=(s+e)>>1;
return Max(M(s,mid),M(mid+1,e));
}
int M2(int s,int e)
{
int ans;
top=0;top2=0;
a[++top]=seg(s,e);k[top]=0;
L:;
if(a[top].s==a[top].e) {ans=p[a[top].s];goto OUT;}
for(;k[top]<2;k[top]++)
{
if(k[top]==0) a[top+1]=seg(a[top].s,(a[top].s+a[top].e)/2);
else a[top+1]=seg((a[top].s+a[top].e)/2+1,a[top].e);
k[top+1]=0;
top++; goto L;
Z:;
}
ans=Max(m[top2],m[top2-1]);
top2-=2;
OUT:;
m[++top2]=ans;--top;if(top)goto Z;else return ans;
}
int main()
{
whi
带返还值的非递归 bs算法为例子
最新推荐文章于 2025-01-22 11:48:27 发布