bool IsTree(vector<int>::iterator &begin,vector<int>::iterator &end)
{
if(distance(begin,end) == 1 || begin == end)
return true;
vector<int>::iterator iter = end;
--iter;
vector<int>::iterator it = find_if(begin,end,bind2nd(greater<int>(),*iter));
if(find_if(it,end,bind2nd(less<int>(),*iter)) != end)
return false;
return IsTree(begin,it) && IsTree(it,iter);
}
{
if(distance(begin,end) == 1 || begin == end)
return true;
vector<int>::iterator iter = end;
--iter;
vector<int>::iterator it = find_if(begin,end,bind2nd(greater<int>(),*iter));
if(find_if(it,end,bind2nd(less<int>(),*iter)) != end)
return false;
return IsTree(begin,it) && IsTree(it,iter);
}