题解:P3836 [IOI 2017] Nowruz

· · 题解

// Algorithm implementation -- C++ --

// Copyright (C) 2001-2014 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version.

// This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // http://www.gnu.org/licenses/.

/*

/** @file bits/stl_algo.h

ifndef _STL_ALGO_H

define _STL_ALGO_H 1

include <cstdlib> // for rand

include <bits/algorithmfwd.h>

include <bits/stl_heap.h>

include <bits/stl_tempbuf.h> // for _Temporary_buffer

include <bits/predefined_ops.h>

if __cplusplus >= 201103L

include <random> // for std::uniform_int_distribution

endif

// See concept_check.h for the _glibcxx*_requires macros.

namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION

/// Swaps the median value of __a, b and *c under comp to *result template<typename _Iterator, typename _Compare> void move_median_to_first(_Iterator result,_Iterator a, _Iterator __b, _Iterator c, _Compare comp) { if (comp(a, b)) { if (comp(b, c)) std::iter_swap(result, b); else if (comp(a, __c)) std::iter_swap(result, c); else std::iter_swap(result, a); } else if (comp(a, __c)) std::iter_swap(result, a); else if (comp(b, c)) std::iter_swap(result, c); else std::iter_swap(result, b); }

/// This is an overload used by find algos for the Input Iterator case. template<typename _InputIterator, typename _Predicate> inline _InputIterator find_if(_InputIterator first, _InputIterator __last, _Predicate pred, input_iterator_tag) { while (first != last && !pred(first)) ++first; return __first; }

/// This is an overload used by find algos for the RAI case. template<typename _RandomAccessIterator, typename _Predicate> _RandomAccessIterator find_if(_RandomAccessIterator first, _RandomAccessIterator last, _Predicate pred, random_access_iterator_tag) { typename iterator_traits<_RandomAccessIterator>::difference_type trip_count = (last - __first) >> 2;

  for (; __trip_count > 0; --__trip_count)
{
  if (__pred(__first))
    return __first;
  ++__first;

  if (__pred(__first))
    return __first;
  ++__first;

  if (__pred(__first))
    return __first;
  ++__first;

  if (__pred(__first))
    return __first;
  ++__first;
}

  switch (__last - __first)
{
case 3:
  if (__pred(__first))
    return __first;
  ++__first;
case 2:
  if (__pred(__first))
    return __first;
  ++__first;
case 1:
  if (__pred(__first))
    return __first;
  ++__first;
case 0:
default:
  return __last;
}
}

template<typename _Iterator, typename _Predicate> inline _Iterator find_if(_Iterator first, _Iterator last, _Predicate pred) { return find_if(first, last, pred, std::__iterator_category(__first)); }

/// Provided for stable_partition to use. template<typename _InputIterator, typename _Predicate> inline _InputIterator find_if_not(_InputIterator __first, _InputIterator last, _Predicate pred) { return std::find_if(first, last, gnu_cxx::ops::negate(pred), std::iterator_category(first)); }

/// Like find_if_not(), but uses and updates a count of the /// remaining range length instead of comparing against an end /// iterator. template<typename _InputIterator, typename _Predicate, typename _Distance> _InputIterator find_if_not_n(_InputIterator first, _Distance& __len, _Predicate pred) { for (; len; --len, ++first) if (!pred(first)) break; return __first; }

// set_difference // set_intersection // set_symmetric_difference // set_union // for_each // find // find_if // find_first_of // adjacent_find // count // count_if // search

template<typename _ForwardIterator1, typename _ForwardIterator2, typename _BinaryPredicate> _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 last1, _ForwardIterator2 first2, _ForwardIterator2 __last2, _BinaryPredicate predicate) { // Test for empty ranges if (first1 == last1 || first2 == last2) return __first1;

  // Test for a pattern of length 1.
  _ForwardIterator2 __p1(__first2);
  if (++__p1 == __last2)
return std::__find_if(__first1, __last1,
    __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));

  // General case.
  _ForwardIterator2 __p;
  _ForwardIterator1 __current = __first1;

  for (;;)
{
  __first1 =
    std::__find_if(__first1, __last1,
    __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));

  if (__first1 == __last1)
    return __last1;

  __p = __p1;
  __current = __first1;
  if (++__current == __last1)
    return __last1;

  while (__predicate(__current, __p))
    {
      if (++__p == __last2)
    return __first1;
      if (++__current == __last1)
    return __last1;
    }
  ++__first1;
}
  return __first1;
}

// search_n

/**

/**

template<typename _ForwardIterator, typename _Integer, typename _UnaryPredicate> _ForwardIterator search_n(_ForwardIterator first, _ForwardIterator last, _Integer __count, _UnaryPredicate unary_pred) { if (count <= 0) return first;

  if (__count == 1)
return std::__find_if(__first, __last, __unary_pred);

  return std::__search_n_aux(__first, __last, __count, __unary_pred,
             std::__iterator_category(__first));
}

// find_end for forward iterators. template<typename _ForwardIterator1, typename _ForwardIterator2, typename _BinaryPredicate> _ForwardIterator1 find_end(_ForwardIterator1 first1, _ForwardIterator1 last1, _ForwardIterator2 __first2, _ForwardIterator2 last2, forward_iterator_tag, forward_iterator_tag, _BinaryPredicate comp) { if (first2 == last2) return last1;

  _ForwardIterator1 __result = __last1;
  while (1)
{
  _ForwardIterator1 __new_result
    = std::__search(__first1, __last1, __first2, __last2, __comp);
  if (__new_result == __last1)
    return __result;
  else
    {
      __result = __new_result;
      __first1 = __new_result;
      ++__first1;
    }
}
}

// find_end for bidirectional iterators (much faster). template<typename _BidirectionalIterator1, typename _BidirectionalIterator2, typename _BinaryPredicate> _BidirectionalIterator1 find_end(_BidirectionalIterator1 first1, _BidirectionalIterator1 last1, _BidirectionalIterator2 __first2, _BidirectionalIterator2 last2, bidirectional_iterator_tag, bidirectional_iterator_tag, _BinaryPredicate comp) { // concept requirements glibcxx_function_requires(_BidirectionalIteratorConcept< _BidirectionalIterator1>) __glibcxx_function_requires(_BidirectionalIteratorConcept< _BidirectionalIterator2>)

  typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1;
  typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2;

  _RevIterator1 __rlast1(__first1);
  _RevIterator2 __rlast2(__first2);
  _RevIterator1 __rresult = std::__search(_RevIterator1(__last1), __rlast1,
                      _RevIterator2(__last2), __rlast2,
                      __comp);

  if (__rresult == __rlast1)
return __last1;
  else
{
  _BidirectionalIterator1 __result = __rresult.base();
  std::advance(__result, -std::distance(__first2, __last2));
  return __result;
}
}

/**

/**

if __cplusplus >= 201103L

/**

/**

/**

/**

/**

/**

template<typename _InputIterator, typename _OutputIterator, typename _Predicate> _OutputIterator remove_copy_if(_InputIterator __first, _InputIterator last, _OutputIterator __result, _Predicate pred) { for (; first != last; ++first) if (!pred(first)) { __result = first; ++result; } return __result; }

/**

/**

if __cplusplus >= 201103L

/**

template<typename _InputIterator, typename _Size, typename _OutputIterator> _OutputIterator copy_n(_InputIterator first, _Size __n, _OutputIterator result, input_iterator_tag) { if (n > 0) { while (true) { __result = first; ++result; if (--n > 0) ++first; else break; } } return __result; }

template<typename _RandomAccessIterator, typename _Size, typename _OutputIterator> inline _OutputIterator copy_n(_RandomAccessIterator first, _Size n, _OutputIterator __result, random_access_iterator_tag) { return std::copy(first, first + n, __result); }

/**

/**

template<typename _ForwardIterator, typename _Predicate> _ForwardIterator remove_if(_ForwardIterator first, _ForwardIterator last, _Predicate pred) { first = std::__find_if(first, last, pred); if (first == last) return __first; _ForwardIterator result = first; ++first; for (; first != last; ++first) if (!pred(first)) { __result = _GLIBCXX_MOVE(first); ++result; } return __result; }

/**

/**

template<typename _ForwardIterator, typename _BinaryPredicate> _ForwardIterator adjacent_find(_ForwardIterator first, _ForwardIterator last, _BinaryPredicate __binary_pred) { if (first == last) return last; _ForwardIterator next = first; while (++next != last) { if (__binary_pred(first, next)) return first; first = next; } return last; }

template<typename _ForwardIterator, typename _BinaryPredicate> _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator last, _BinaryPredicate binary_pred) { // Skip the beginning, if already unique. first = std::adjacent_find(first, last, binary_pred); if (first == last) return __last;

  // Do the real copy work.
  _ForwardIterator __dest = __first;
  ++__first;
  while (++__first != __last)
if (!__binary_pred(__dest, __first))
  *++__dest = _GLIBCXX_MOVE(*__first);
  return ++__dest;
}

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/// This is a helper function for the rotate algorithm. template<typename _ForwardIterator> void rotate(_ForwardIterator __first, _ForwardIterator middle, _ForwardIterator last, forward_iterator_tag) { if (first == middle || last == __middle) return;

  _ForwardIterator __first2 = __middle;
  do
{
  std::iter_swap(__first, __first2);
  ++__first;
  ++__first2;
  if (__first == __middle)
    __middle = __first2;
}
  while (__first2 != __last);

  __first2 = __middle;

  while (__first2 != __last)
{
  std::iter_swap(__first, __first2);
  ++__first;
  ++__first2;
  if (__first == __middle)
    __middle = __first2;
  else if (__first2 == __last)
    __first2 = __middle;
}
}

/// This is a helper function for the rotate algorithm. template<typename _BidirectionalIterator> void rotate(_BidirectionalIterator __first, _BidirectionalIterator middle, _BidirectionalIterator last, bidirectional_iterator_tag) { // concept requirements glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept< _BidirectionalIterator>)

  if (__first == __middle || __last  == __middle)
return;

  std::__reverse(__first,  __middle, bidirectional_iterator_tag());
  std::__reverse(__middle, __last,   bidirectional_iterator_tag());

  while (__first != __middle && __middle != __last)
{
  std::iter_swap(__first, --__last);
  ++__first;
}

  if (__first == __middle)
std::__reverse(__middle, __last,   bidirectional_iterator_tag());
  else
std::__reverse(__first,  __middle, bidirectional_iterator_tag());
}

/// This is a helper function for the rotate algorithm. template<typename _RandomAccessIterator> void rotate(_RandomAccessIterator __first, _RandomAccessIterator middle, _RandomAccessIterator __last, random_access_iterator_tag) { // concept requirements __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< _RandomAccessIterator>)

  if (__first == __middle || __last  == __middle)
return;

  typedef typename iterator_traits<_RandomAccessIterator>::difference_type
_Distance;
  typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;

  _Distance __n = __last   - __first;
  _Distance __k = __middle - __first;

  if (__k == __n - __k)
{
  std::swap_ranges(__first, __middle, __middle);
  return;
}

  _RandomAccessIterator __p = __first;

  for (;;)
{
  if (__k < __n - __k)
    {
      if (__is_pod(_ValueType) && __k == 1)
    {
      _ValueType __t = _GLIBCXX_MOVE(*__p);
      _GLIBCXX_MOVE3(__p + 1, __p + __n, __p);
      *(__p + __n - 1) = _GLIBCXX_MOVE(__t);
      return;
    }
      _RandomAccessIterator __q = __p + __k;
      for (_Distance __i = 0; __i < __n - __k; ++ __i)
    {
      std::iter_swap(__p, __q);
      ++__p;
      ++__q;
    }
      __n %= __k;
      if (__n == 0)
    return;
      std::swap(__n, __k);
      __k = __n - __k;
    }
  else
    {
      __k = __n - __k;
      if (__is_pod(_ValueType) && __k == 1)
    {
      _ValueType __t = _GLIBCXX_MOVE(*(__p + __n - 1));
      _GLIBCXX_MOVE_BACKWARD3(__p, __p + __n - 1, __p + __n);
      *__p = _GLIBCXX_MOVE(__t);
      return;
    }
      _RandomAccessIterator __q = __p + __n;
      __p = __q - __k;
      for (_Distance __i = 0; __i < __n - __k; ++ __i)
    {
      --__p;
      --__q;
      std::iter_swap(__p, __q);
    }
      __n %= __k;
      if (__n == 0)
    return;
      std::swap(__n, __k);
    }
}
}

/**

/**

/// This is a helper function... template<typename _ForwardIterator, typename _Predicate> _ForwardIterator partition(_ForwardIterator __first, _ForwardIterator last, _Predicate pred, forward_iterator_tag) { if (first == last) return first;

  while (__pred(*__first))
if (++__first == __last)
  return __first;

  _ForwardIterator __next = __first;

  while (++__next != __last)
if (__pred(*__next))
  {
    std::iter_swap(__first, __next);
    ++__first;
  }

  return __first;
}

/// This is a helper function... template<typename _BidirectionalIterator, typename _Predicate> _BidirectionalIterator partition(_BidirectionalIterator __first, _BidirectionalIterator last, _Predicate pred, bidirectional_iterator_tag) { while (true) { while (true) if (first == last) return first; else if (pred(*first)) ++first; else break; --last; while (true) if (first == last) return first; else if (!bool(pred(*last))) --last; else break; std::iter_swap(first, last); ++__first; } }

// partition

/// This is a helper function... /// Requires len != 0 and !pred(*first), /// same as stable_partition_adaptive. template<typename _ForwardIterator, typename _Predicate, typename _Distance> _ForwardIterator inplace_stable_partition(_ForwardIterator __first, _Predicate pred, _Distance len) { if (len == 1) return first; _ForwardIterator middle = first; std::advance(middle, len / 2); _ForwardIterator left_split = std::inplace_stable_partition(first, pred, len / 2); // Advance past true-predicate values to satisfy this // function's preconditions. _Distance right_len = len - len / 2; _ForwardIterator right_split = std::find_if_not_n(middle, right_len, pred); if (right_len) __right_split = std::inplace_stable_partition(middle, pred, right_len); std::rotate(__left_split, middle, right_split); std::advance(__left_split, std::distance(middle, __right_split)); return __left_split; }

/// This is a helper function... /// Requires first != last and !pred(first) /// and len == distance(first, last). /// /// !pred(first) allows us to guarantee that we don't /// move-assign an element onto itself. template<typename _ForwardIterator, typename _Pointer, typename _Predicate, typename _Distance> _ForwardIterator __stable_partition_adaptive(_ForwardIterator first, _ForwardIterator last, _Predicate __pred, _Distance len, _Pointer buffer, _Distance __buffer_size) { if (len <= buffer_size) { _ForwardIterator result1 = first; _Pointer result2 = buffer; // The precondition guarantees that !pred(first), so // move that element to the buffer before starting the loop. // This ensures that we only call pred once per element. *result2 = _GLIBCXX_MOVE(first); ++result2; ++first; for (; first != last; ++first) if (pred(first)) { result1 = _GLIBCXX_MOVE(*first); ++result1; } else { *result2 = _GLIBCXX_MOVE(*first); ++result2; } _GLIBCXX_MOVE3(buffer, result2, result1); return result1; } else { _ForwardIterator middle = first; std::advance(middle, len / 2); _ForwardIterator __left_split = std::stable_partition_adaptive(first, middle, pred, len / 2, buffer, buffer_size); // Advance past true-predicate values to satisfy this // function's preconditions. _Distance right_len = len - len / 2; _ForwardIterator right_split = std::find_if_not_n(middle, right_len, pred); if (right_len) __right_split = std::stable_partition_adaptive(right_split, last, pred, __right_len, buffer, buffer_size); std::rotate(__left_split, middle, right_split); std::advance(__left_split, std::distance(middle, __right_split)); return __left_split; } }

template<typename _ForwardIterator, typename _Predicate> _ForwardIterator stable_partition(_ForwardIterator first, _ForwardIterator __last, _Predicate pred) { first = std::find_if_not(first, last, pred);

  if (__first == __last)
return __first;

  typedef typename iterator_traits<_ForwardIterator>::value_type
_ValueType;
  typedef typename iterator_traits<_ForwardIterator>::difference_type
_DistanceType;

  _Temporary_buffer<_ForwardIterator, _ValueType> __buf(__first, __last);
  if (__buf.size() > 0)
return
  std::__stable_partition_adaptive(__first, __last, __pred,
                   _DistanceType(__buf.requested_size()),
                   __buf.begin(),
                   _DistanceType(__buf.size()));
  else
return
  std::__inplace_stable_partition(__first, __pred,
                  _DistanceType(__buf.requested_size()));
}

/**

/// This is a helper function for the sort routines. template<typename _RandomAccessIterator, typename _Compare> void heap_select(_RandomAccessIterator first, _RandomAccessIterator middle, _RandomAccessIterator __last, _Compare comp) { std::make_heap(first, middle, __comp); for (_RandomAccessIterator i = middle; i < last; ++i) if (comp(i, first)) std::pop_heap(first, middle, i, comp); }

// partial_sort

template<typename _InputIterator, typename _RandomAccessIterator, typename _Compare> _RandomAccessIterator partial_sort_copy(_InputIterator __first, _InputIterator last, _RandomAccessIterator result_first, _RandomAccessIterator result_last, _Compare __comp) { typedef typename iterator_traits<_InputIterator>::value_type _InputValueType; typedef iterator_traits<_RandomAccessIterator> _RItTraits; typedef typename _RItTraits::difference_type _DistanceType;

  if (__result_first == __result_last)
return __result_last;
  _RandomAccessIterator __result_real_last = __result_first;
  while (__first != __last && __result_real_last != __result_last)
{
  *__result_real_last = *__first;
  ++__result_real_last;
  ++__first;
}

  std::__make_heap(__result_first, __result_real_last, __comp);
  while (__first != __last)
{
  if (__comp(__first, __result_first))
    std::__adjust_heap(__result_first, _DistanceType(0),
               _DistanceType(__result_real_last
                     - __result_first),
               _InputValueType(*__first), __comp);
  ++__first;
}
  std::__sort_heap(__result_first, __result_real_last, __comp);
  return __result_real_last;
}

/**

/**

/// This is a helper function for the sort routine. template<typename _RandomAccessIterator, typename _Compare> void unguarded_linear_insert(_RandomAccessIterator __last, _Compare comp) { typename iterator_traits<_RandomAccessIterator>::value_type val = _GLIBCXX_MOVE(*last); _RandomAccessIterator next = last; --next; while (comp(val, next)) { __last = _GLIBCXX_MOVE(next); last = next; --next; } *last = _GLIBCXX_MOVE(val); }

/// This is a helper function for the sort routine. template<typename _RandomAccessIterator, typename _Compare> void insertion_sort(_RandomAccessIterator first, _RandomAccessIterator __last, _Compare comp) { if (first == __last) return;

  for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
{
  if (__comp(__i, __first))
    {
      typename iterator_traits<_RandomAccessIterator>::value_type
    __val = _GLIBCXX_MOVE(*__i);
      _GLIBCXX_MOVE_BACKWARD3(__first, __i, __i + 1);
      *__first = _GLIBCXX_MOVE(__val);
    }
  else
    std::__unguarded_linear_insert(__i,
            __gnu_cxx::__ops::__val_comp_iter(__comp));
}
}

/// This is a helper function for the sort routine. template<typename _RandomAccessIterator, typename _Compare> inline void unguarded_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator last, _Compare comp) { for (_RandomAccessIterator i = first; i != last; ++i) std::unguarded_linear_insert(i, gnu_cxx::ops::val_comp_iter(comp)); }

/**

/// This is a helper function for the sort routine. template<typename _RandomAccessIterator, typename _Compare> void final_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator last, _Compare comp) { if (last - first > int(_S_threshold)) { std::insertion_sort(first, first + int(_S_threshold), comp); std::unguarded_insertion_sort(first + int(_S_threshold), last, comp); } else std::insertion_sort(first, last, __comp); }

/// This is a helper function... template<typename _RandomAccessIterator, typename _Compare> _RandomAccessIterator unguarded_partition(_RandomAccessIterator first, _RandomAccessIterator last, _RandomAccessIterator __pivot, _Compare comp) { while (true) { while (comp(first, pivot)) ++first; --last; while (comp(pivot, last)) --last; if (!(first < last)) return first; std::iter_swap(first, last); ++__first; } }

/// This is a helper function... template<typename _RandomAccessIterator, typename _Compare> inline _RandomAccessIterator unguarded_partition_pivot(_RandomAccessIterator __first, _RandomAccessIterator last, _Compare comp) { _RandomAccessIterator mid = first + (last - first) / 2; std::__move_median_to_first(first, first + 1, mid, last - 1, comp); return std::__unguarded_partition(first + 1, last, first, comp); }

template<typename _RandomAccessIterator, typename _Compare> inline void partial_sort(_RandomAccessIterator first, _RandomAccessIterator middle, _RandomAccessIterator __last, _Compare comp) { std::heap_select(first, middle, last, comp); std::__sort_heap(first, middle, comp); }

/// This is a helper function for the sort routine. template<typename _RandomAccessIterator, typename _Size, typename _Compare> void introsort_loop(_RandomAccessIterator first, _RandomAccessIterator last, _Size depth_limit, _Compare comp) { while (last - first > int(_S_threshold)) { if (__depth_limit == 0) { std::partial_sort(first, last, last, comp); return; } --depth_limit; _RandomAccessIterator cut = std::unguarded_partition_pivot(first, last, comp); std::introsort_loop(cut, last, __depth_limit, comp); last = cut; } }

// sort

template<typename _RandomAccessIterator, typename _Compare> inline void sort(_RandomAccessIterator __first, _RandomAccessIterator last, _Compare comp) { if (first != last) { std::introsort_loop(first, last, std::lg(last - first) * 2, comp); std::final_insertion_sort(first, last, comp); } }

template<typename _RandomAccessIterator, typename _Size, typename _Compare> void introselect(_RandomAccessIterator __first, _RandomAccessIterator nth, _RandomAccessIterator last, _Size depth_limit, _Compare comp) { while (last - first > 3) { if (__depth_limit == 0) { std::heap_select(first, nth + 1, last, comp); // Place the nth largest element in its final position. std::iter_swap(first, nth); return; } --depth_limit; _RandomAccessIterator cut = std::unguarded_partition_pivot(first, last, comp); if (cut <= nth) first = cut; else last = cut; } std::__insertion_sort(first, last, __comp); }

// nth_element

// lower_bound moved to stl_algobase.h

/**

template<typename _ForwardIterator, typename _Tp, typename _Compare> _ForwardIterator upper_bound(_ForwardIterator first, _ForwardIterator last, const _Tp& __val, _Compare comp) { typedef typename iterator_traits<_ForwardIterator>::difference_type _DistanceType;

  _DistanceType __len = std::distance(__first, __last);

  while (__len > 0)
{
  _DistanceType __half = __len >> 1;
  _ForwardIterator __middle = __first;
  std::advance(__middle, __half);
  if (__comp(__val, __middle))
    __len = __half;
  else
    {
      __first = __middle;
      ++__first;
      __len = __len - __half - 1;
    }
}
  return __first;
}

/**

/**

template<typename _ForwardIterator, typename _Tp, typename _CompareItTp, typename _CompareTpIt> pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator first, _ForwardIterator last, const _Tp& __val, _CompareItTp comp_it_val, _CompareTpIt __comp_val_it) { typedef typename iterator_traits<_ForwardIterator>::difference_type _DistanceType;

  _DistanceType __len = std::distance(__first, __last);

  while (__len > 0)
{
  _DistanceType __half = __len >> 1;
  _ForwardIterator __middle = __first;
  std::advance(__middle, __half);
  if (__comp_it_val(__middle, __val))
    {
      __first = __middle;
      ++__first;
      __len = __len - __half - 1;
    }
  else if (__comp_val_it(__val, __middle))
    __len = __half;
  else
    {
      _ForwardIterator __left
    = std::__lower_bound(__first, __middle, __val, __comp_it_val);
      std::advance(__first, __len);
      _ForwardIterator __right
    = std::__upper_bound(++__middle, __first, __val, __comp_val_it);
      return pair<_ForwardIterator, _ForwardIterator>(__left, __right);
    }
}
  return pair<_ForwardIterator, _ForwardIterator>(__first, __first);
}

/**

/**

/**

/**

// merge

/// This is a helper function for the merge_adaptive routines. template<typename _InputIterator1, typename _InputIterator2, typename _OutputIterator, typename _Compare> void __move_merge_adaptive(_InputIterator1 first1, _InputIterator1 last1, _InputIterator2 __first2, _InputIterator2 last2, _OutputIterator __result, _Compare comp) { while (first1 != last1 && first2 != last2) { if (comp(first2, first1)) { __result = _GLIBCXX_MOVE(first2); ++first2; } else { __result = _GLIBCXX_MOVE(first1); ++first1; } ++result; } if (first1 != last1) _GLIBCXX_MOVE3(first1, last1, result); }

/// This is a helper function for the merge_adaptive routines. template<typename _BidirectionalIterator1, typename _BidirectionalIterator2, typename _BidirectionalIterator3, typename _Compare> void move_merge_adaptive_backward(_BidirectionalIterator1 first1, _BidirectionalIterator1 last1, _BidirectionalIterator2 first2, _BidirectionalIterator2 __last2, _BidirectionalIterator3 result, _Compare comp) { if (first1 == __last1) { _GLIBCXX_MOVE_BACKWARD3(first2, last2, result); return; } else if (first2 == __last2) return;

  --__last1;
  --__last2;
  while (true)
{
  if (__comp(__last2, __last1))
    {
      *--__result = _GLIBCXX_MOVE(*__last1);
      if (__first1 == __last1)
    {
      _GLIBCXX_MOVE_BACKWARD3(__first2, ++__last2, __result);
      return;
    }
      --__last1;
    }
  else
    {
      *--__result = _GLIBCXX_MOVE(*__last2);
      if (__first2 == __last2)
    return;
      --__last2;
    }
}
}

/// This is a helper function for the merge routines. template<typename _BidirectionalIterator1, typename _BidirectionalIterator2, typename _Distance> _BidirectionalIterator1 rotate_adaptive(_BidirectionalIterator1 first, _BidirectionalIterator1 middle, _BidirectionalIterator1 __last, _Distance len1, _Distance len2, _BidirectionalIterator2 __buffer, _Distance buffer_size) { _BidirectionalIterator2 buffer_end; if (len1 > len2 && len2 <= buffer_size) { if (len2) { buffer_end = _GLIBCXX_MOVE3(middle, last, __buffer); _GLIBCXX_MOVE_BACKWARD3(first, middle, last); return _GLIBCXX_MOVE3(buffer, buffer_end, first); } else return first; } else if (len1 <= buffer_size) { if (len1) { buffer_end = _GLIBCXX_MOVE3(first, middle, buffer); _GLIBCXX_MOVE3(middle, last, first); return _GLIBCXX_MOVE_BACKWARD3(buffer, buffer_end, last); } else return last; } else { std::rotate(first, middle, last); std::advance(first, std::distance(middle, last)); return __first; } }

/// This is a helper function for the merge routines. template<typename _BidirectionalIterator, typename _Distance, typename _Pointer, typename _Compare> void merge_adaptive(_BidirectionalIterator first, _BidirectionalIterator middle, _BidirectionalIterator __last, _Distance len1, _Distance len2, _Pointer __buffer, _Distance buffer_size, _Compare comp) { if (len1 <= len2 && len1 <= buffer_size) { _Pointer buffer_end = _GLIBCXX_MOVE3(first, middle, buffer); std::move_merge_adaptive(buffer, buffer_end, middle, last, first, comp); } else if (len2 <= buffer_size) { _Pointer buffer_end = _GLIBCXX_MOVE3(middle, last, buffer); std::move_merge_adaptive_backward(first, middle, buffer, buffer_end, last, comp); } else { _BidirectionalIterator first_cut = first; _BidirectionalIterator __second_cut = middle; _Distance len11 = 0; _Distance len22 = 0; if (len1 > len2) { len11 = len1 / 2; std::advance(first_cut, len11); second_cut = std::__lower_bound(middle, last, *first_cut, gnu_cxx::ops::iter_comp_val(comp)); len22 = std::distance(middle, second_cut); } else { len22 = len2 / 2; std::advance(second_cut, len22); first_cut = std::upper_bound(first, middle, *__second_cut, gnu_cxx::ops::val_comp_iter(comp)); len11 = std::distance(first, first_cut); } _BidirectionalIterator new_middle = std::__rotate_adaptive(first_cut, middle, second_cut, len1 - len11, len22, buffer, buffer_size); std::__merge_adaptive(first, first_cut, __new_middle, len11, len22, buffer, buffer_size, comp); std::merge_adaptive(new_middle, second_cut, last, len1 - len11, len2 - len22, buffer, __buffer_size, comp); } }

/// This is a helper function for the merge routines. template<typename _BidirectionalIterator, typename _Distance, typename _Compare> void merge_without_buffer(_BidirectionalIterator __first, _BidirectionalIterator middle, _BidirectionalIterator last, _Distance __len1, _Distance len2, _Compare comp) { if (len1 == 0 || len2 == 0) return; if (len1 + len2 == 2) { if (comp(middle, first)) std::iter_swap(first, middle); return; } _BidirectionalIterator first_cut = __first; _BidirectionalIterator second_cut = middle; _Distance __len11 = 0; _Distance len22 = 0; if (len1 > len2) { len11 = len1 / 2; std::advance(first_cut, len11); second_cut = std::lower_bound(middle, last, first_cut, __gnu_cxx::ops::iter_comp_val(comp)); len22 = std::distance(middle, second_cut); } else { len22 = len2 / 2; std::advance(__second_cut, len22); first_cut = std::__upper_bound(first, __middle, second_cut, __gnu_cxx::ops::val_comp_iter(comp)); len11 = std::distance(first, first_cut); } std::rotate(__first_cut, middle, second_cut); _BidirectionalIterator new_middle = first_cut; std::advance(__new_middle, std::distance(middle, second_cut)); std::merge_without_buffer(first, __first_cut, new_middle, len11, len22, comp); std::merge_without_buffer(new_middle, __second_cut, last, len1 - len11, len2 - len22, __comp); }

template<typename _BidirectionalIterator, typename _Compare> void inplace_merge(_BidirectionalIterator first, _BidirectionalIterator middle, _BidirectionalIterator __last, _Compare comp) { typedef typename iterator_traits<_BidirectionalIterator>::value_type _ValueType; typedef typename iterator_traits<_BidirectionalIterator>::difference_type _DistanceType;

  if (__first == __middle || __middle == __last)
return;

  const _DistanceType __len1 = std::distance(__first, __middle);
  const _DistanceType __len2 = std::distance(__middle, __last);

  typedef _Temporary_buffer<_BidirectionalIterator, _ValueType> _TmpBuf;
  _TmpBuf __buf(__first, __last);

  if (__buf.begin() == 0)
std::__merge_without_buffer
  (__first, __middle, __last, __len1, __len2, __comp);
  else
std::__merge_adaptive
  (__first, __middle, __last, __len1, __len2, __buf.begin(),
   _DistanceType(__buf.size()), __comp);
}

/**

/**

/// This is a helper function for the merge_sort_loop routines. template<typename _InputIterator, typename _OutputIterator, typename _Compare> _OutputIterator move_merge(_InputIterator first1, _InputIterator __last1, _InputIterator first2, _InputIterator last2, _OutputIterator __result, _Compare comp) { while (first1 != last1 && first2 != last2) { if (comp(first2, first1)) { *result = _GLIBCXX_MOVE(first2); ++first2; } else { result = _GLIBCXX_MOVE(*first1); ++first1; } ++result; } return _GLIBCXX_MOVE3(first2, last2, _GLIBCXX_MOVE3(first1, last1, __result)); }

template<typename _RandomAccessIterator1, typename _RandomAccessIterator2, typename _Distance, typename _Compare> void merge_sort_loop(_RandomAccessIterator1 __first, _RandomAccessIterator1 last, _RandomAccessIterator2 result, _Distance step_size, _Compare comp) { const _Distance two_step = 2 * __step_size;

  while (__last - __first >= __two_step)
{
  __result = std::__move_merge(__first, __first + __step_size,
                   __first + __step_size,
                   __first + __two_step,
                   __result, __comp);
  __first += __two_step;
}
  __step_size = std::min(_Distance(__last - __first), __step_size);

  std::__move_merge(__first, __first + __step_size,
        __first + __step_size, __last, __result, __comp);
}

template<typename _RandomAccessIterator, typename _Distance, typename _Compare> void chunk_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator last, _Distance chunk_size, _Compare comp) { while (last - first >= chunk_size) { std::__insertion_sort(first, first + chunk_size, comp); first += chunk_size; } std::__insertion_sort(first, last, comp); }

enum { _S_chunk_size = 7 };

template<typename _RandomAccessIterator, typename _Pointer, typename _Compare> void merge_sort_with_buffer(_RandomAccessIterator first, _RandomAccessIterator last, _Pointer __buffer, _Compare comp) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type _Distance;

  const _Distance __len = __last - __first;
  const _Pointer __buffer_last = __buffer + __len;

  _Distance __step_size = _S_chunk_size;
  std::__chunk_insertion_sort(__first, __last, __step_size, __comp);

  while (__step_size < __len)
{
  std::__merge_sort_loop(__first, __last, __buffer,
             __step_size, __comp);
  __step_size *= 2;
  std::__merge_sort_loop(__buffer, __buffer_last, __first,
             __step_size, __comp);
  __step_size *= 2;
}
}

template<typename _RandomAccessIterator, typename _Pointer, typename _Distance, typename _Compare> void stable_sort_adaptive(_RandomAccessIterator __first, _RandomAccessIterator last, _Pointer buffer, _Distance buffer_size, _Compare comp) { const _Distance len = (last - first + 1) / 2; const _RandomAccessIterator middle = first + len; if (len > buffer_size) { std::stable_sort_adaptive(first, middle, buffer, __buffer_size, comp); std::stable_sort_adaptive(middle, last, buffer, buffer_size, comp); } else { std::merge_sort_with_buffer(first, middle, buffer, comp); std::merge_sort_with_buffer(middle, last, buffer, comp); } std::merge_adaptive(first, middle, __last, _Distance(middle - first), _Distance(last - middle), buffer, buffer_size, comp); }

/// This is a helper function for the stable sorting routines. template<typename _RandomAccessIterator, typename _Compare> void inplace_stable_sort(_RandomAccessIterator __first, _RandomAccessIterator last, _Compare comp) { if (last - first < 15) { std::insertion_sort(first, last, __comp); return; } _RandomAccessIterator middle = first + (last - first) / 2; std::inplace_stable_sort(first, middle, comp); std::inplace_stable_sort(middle, last, comp); std::merge_without_buffer(first, middle, last, middle - first, last - middle, __comp); }

// stable_sort

// Set algorithms: includes, set_union, set_intersection, set_difference, // set_symmetric_difference. All of these algorithms have the precondition // that their input ranges are sorted and the postcondition that their output // ranges are sorted.

template<typename _InputIterator1, typename _InputIterator2, typename _Compare> bool includes(_InputIterator1 __first1, _InputIterator1 last1, _InputIterator2 first2, _InputIterator2 __last2, _Compare comp) { while (first1 != last1 && first2 != last2) if (comp(first2, first1)) return false; else if (comp(first1, first2)) ++first1; else ++first1, ++__first2;

  return __first2 == __last2;
}

/**

/**

// nth_element // merge // set_difference // set_intersection // set_union // stable_sort // set_symmetric_difference // min_element // max_element

template<typename _BidirectionalIterator, typename _Compare> bool next_permutation(_BidirectionalIterator first, _BidirectionalIterator last, _Compare comp) { if (first == __last) return false; _BidirectionalIterator i = first; ++i; if (i == last) return false; i = last; --__i;

  for(;;)
{
  _BidirectionalIterator __ii = __i;
  --__i;
  if (__comp(__i, __ii))
    {
      _BidirectionalIterator __j = __last;
      while (!__comp(__i, --__j))
    {}
      std::iter_swap(__i, __j);
      std::__reverse(__ii, __last,
             std::__iterator_category(__first));
      return true;
    }
  if (__i == __first)
    {
      std::__reverse(__first, __last,
             std::__iterator_category(__first));
      return false;
    }
}
}

/**

/**

template<typename _BidirectionalIterator, typename _Compare> bool prev_permutation(_BidirectionalIterator first, _BidirectionalIterator last, _Compare comp) { if (first == __last) return false; _BidirectionalIterator i = first; ++i; if (i == last) return false; i = last; --__i;

  for(;;)
{
  _BidirectionalIterator __ii = __i;
  --__i;
  if (__comp(__ii, __i))
    {
      _BidirectionalIterator __j = __last;
      while (!__comp(--__j, __i))
    {}
      std::iter_swap(__i, __j);
      std::__reverse(__ii, __last,
             std::__iterator_category(__first));
      return true;
    }
  if (__i == __first)
    {
      std::__reverse(__first, __last,
             std::__iterator_category(__first));
      return false;
    }
}
}

/**

/**

// replace // replace_if

template<typename _InputIterator, typename _OutputIterator, typename _Predicate, typename _Tp> _OutputIterator replace_copy_if(_InputIterator __first, _InputIterator last, _OutputIterator result, _Predicate __pred, const _Tp& new_value) { for (; first != last; ++first, ++result) if (pred(first)) result = new_value; else result = *first; return __result; }

/**

/**

template<typename _InputIterator, typename _Predicate> typename iterator_traits<_InputIterator>::difference_type count_if(_InputIterator first, _InputIterator last, _Predicate __pred) { typename iterator_traits<_InputIterator>::difference_type n = 0; for (; first != last; ++first) if (pred(first)) ++n; return __n; }

if __cplusplus >= 201103L

/**

/**

template<typename _ForwardIterator, typename _Compare> _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator last, _Compare comp) { if (first == last) return last;

  _ForwardIterator __next = __first;
  for (++__next; __next != __last; __first = __next, ++__next)
if (__comp(__next, __first))
  return __next;
  return __next;
}

/**

/**

/**

/**

template<typename _ForwardIterator, typename _Compare> pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator first, _ForwardIterator last, _Compare __comp) { _ForwardIterator next = first; if (first == last || ++next == __last) return std::make_pair(first, first);

  _ForwardIterator __min, __max;
  if (__comp(__next, __first))
{
  __min = __next;
  __max = __first;
}
  else
{
  __min = __first;
  __max = __next;
}

  __first = __next;
  ++__first;

  while (__first != __last)
{
  __next = __first;
  if (++__next == __last)
    {
      if (__comp(__first, __min))
    __min = __first;
      else if (!__comp(__first, __max))
    __max = __first;
      break;
    }

  if (__comp(__next, __first))
    {
      if (__comp(__next, __min))
    __min = __next;
      if (!__comp(__first, __max))
    __max = __first;
    }
  else
    {
      if (__comp(__first, __min))
    __min = __first;
      if (!__comp(__next, __max))
    __max = __next;
    }

  __first = __next;
  ++__first;
}

  return std::make_pair(__min, __max);
}

/**

/**

// N2722 + DR 915. template<typename _Tp> inline _Tp min(initializer_list<_Tp> __l) { return *std::min_element(l.begin(), l.end()); }

template<typename _Tp, typename _Compare> inline _Tp min(initializer_list<_Tp> l, _Compare __comp) { return *std::min_element(l.begin(), l.end(), comp); }

template<typename _Tp> inline _Tp max(initializer_list<_Tp> __l) { return *std::max_element(l.begin(), l.end()); }

template<typename _Tp, typename _Compare> inline _Tp max(initializer_list<_Tp> l, _Compare __comp) { return *std::max_element(l.begin(), l.end(), comp); }

template<typename _Tp> inline pair<_Tp, _Tp> minmax(initializer_list<_Tp> l) { pair<const _Tp, const _Tp> p = std::minmax_element(l.begin(), l.end()); return std::make_pair(__p.first, __p.second); }

template<typename _Tp, typename _Compare> inline pair<_Tp, _Tp> minmax(initializer_list<_Tp> l, _Compare comp) { pair<const _Tp, const _Tp> p = std::minmax_element(l.begin(), l.end(), comp); return std::make_pair(__p.first, __p.second); }

template<typename _ForwardIterator1, typename _ForwardIterator2, typename _BinaryPredicate> bool is_permutation(_ForwardIterator1 first1, _ForwardIterator1 last1, _ForwardIterator2 __first2, _BinaryPredicate pred) { // Efficiently compare identical prefixes: O(N) if sequences // have the same elements in the same order. for (; first1 != last1; ++first1, ++first2) if (!pred(first1, __first2)) break;

  if (__first1 == __last1)
return true;

  // Establish __last2 assuming equal ranges by iterating over the
  // rest of the list.
  _ForwardIterator2 __last2 = __first2;
  std::advance(__last2, std::distance(__first1, __last1));
  for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
{
  if (__scan != std::__find_if(__first1, __scan,
          __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
    continue; // We've seen this one before.

  auto __matches
    = std::__count_if(__first2, __last2,
        __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
  if (0 == __matches ||
      std::__count_if(__scan, __last1,
        __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
      != __matches)
    return false;
}
  return true;
}

/**

/**

if __cplusplus > 201103L

template<typename _ForwardIterator1, typename _ForwardIterator2, typename _BinaryPredicate> bool is_permutation(_ForwardIterator1 first1, _ForwardIterator1 last1, _ForwardIterator2 __first2, _ForwardIterator2 last2, _BinaryPredicate pred) { using _Cat1 = typename iterator_traits<_ForwardIterator1>::iterator_category; using _Cat2 = typename iterator_traits<_ForwardIterator2>::iterator_category; using _It1_is_RA = is_same<_Cat1, random_access_iterator_tag>; using _It2_is_RA = is_same<_Cat2, random_access_iterator_tag>; constexpr bool ra_iters = _It1_is_RA() && _It2_is_RA(); if (__ra_iters) { auto d1 = std::distance(first1, last1); auto d2 = std::distance(first2, last2); if (d1 != d2) return false; }

  // Efficiently compare identical prefixes:  O(N) if sequences
  // have the same elements in the same order.
  for (; __first1 != __last1; ++__first1, ++__first2)
if (!__pred(__first1, __first2))
  break;

  if (__ra_iters)
{
  if (__first1 == __last1)
    return true;
}
  else
{
  auto __d1 = std::distance(__first1, __last1);
  auto __d2 = std::distance(__first2, __last2);
  if (__d1 == 0 && __d2 == 0)
    return true;
  if (__d1 != __d2)
    return false;
}

  for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
{
  if (__scan != std::__find_if(__first1, __scan,
        __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
    continue; // We've seen this one before.

  auto __matches = std::__count_if(__first2, __last2,
    __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
  if (0 == __matches
      || std::__count_if(__scan, __last1,
        __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
      != __matches)
    return false;
}
  return true;
}

/**

/**

ifdef _GLIBCXX_USE_C99_STDINT_TR1

/**

endif // C++11

_GLIBCXX_END_NAMESPACE_VERSION

_GLIBCXX_BEGIN_NAMESPACE_ALGO

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

/**

template<typename _InputIterator1, typename _InputIterator2, typename _OutputIterator, typename _Compare> _OutputIterator merge(_InputIterator1 __first1, _InputIterator1 last1, _InputIterator2 first2, _InputIterator2 __last2, _OutputIterator result, _Compare comp) { while (first1 != last1 && first2 != last2) { if (comp(first2, first1)) { __result = first2; ++first2; } else { __result = first1; ++first1; } ++result; } return std::copy(first2, last2, std::copy(first1, last1, result)); }

/**

/**

template<typename _RandomAccessIterator, typename _Compare> inline void stable_sort(_RandomAccessIterator first, _RandomAccessIterator __last, _Compare __comp) { typedef typename iterator_traits<_RandomAccessIterator>::value_type _ValueType; typedef typename iterator_traits<_RandomAccessIterator>::difference_type _DistanceType;

  typedef _Temporary_buffer<_RandomAccessIterator, _ValueType> _TmpBuf;
  _TmpBuf __buf(__first, __last);

  if (__buf.begin() == 0)
std::__inplace_stable_sort(__first, __last, __comp);
  else
std::__stable_sort_adaptive(__first, __last, __buf.begin(),
                _DistanceType(__buf.size()), __comp);
}

/**

/**

template<typename _InputIterator1, typename _InputIterator2, typename _OutputIterator, typename _Compare> _OutputIterator set_union(_InputIterator1 first1, _InputIterator1 last1, _InputIterator2 __first2, _InputIterator2 last2, _OutputIterator __result, _Compare comp) { while (first1 != last1 && first2 != last2) { if (comp(first1, first2)) { __result = first1; ++first1; } else if (comp(first2, first1)) { *result = first2; ++first2; } else { result = *first1; ++first1; ++first2; } ++result; } return std::copy(first2, last2, std::copy(first1, last1, result)); }

/**

/**

template<typename _InputIterator1, typename _InputIterator2, typename _OutputIterator, typename _Compare> _OutputIterator set_intersection(_InputIterator1 first1, _InputIterator1 last1, _InputIterator2 __first2, _InputIterator2 last2, _OutputIterator __result, _Compare comp) { while (first1 != last1 && first2 != last2) if (comp(first1, first2)) ++first1; else if (comp(first2, first1)) ++first2; else { *result = *first1; ++first1; ++first2; ++result; } return __result; }

/**

/**

template<typename _InputIterator1, typename _InputIterator2, typename _OutputIterator, typename _Compare> _OutputIterator set_difference(_InputIterator1 first1, _InputIterator1 last1, _InputIterator2 __first2, _InputIterator2 last2, _OutputIterator __result, _Compare comp) { while (first1 != last1 && first2 != last2) if (comp(first1, first2)) { __result = first1; ++first1; ++result; } else if (comp(first2, first1)) ++first2; else { ++first1; ++first2; } return std::copy(first1, last1, result); }

/**

/**

template<typename _InputIterator1, typename _InputIterator2, typename _OutputIterator, typename _Compare> _OutputIterator set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 last1, _InputIterator2 first2, _InputIterator2 __last2, _OutputIterator result, _Compare comp) { while (first1 != last1 && first2 != last2) if (comp(first1, first2)) { __result = first1; ++first1; ++result; } else if (comp(first2, first1)) { __result = first2; ++first2; ++result; } else { ++first1; ++first2; } return std::copy(first2, last2, std::copy(first1, last1, result)); }

/**

/**

template<typename _ForwardIterator, typename _Compare> _ForwardIterator min_element(_ForwardIterator first, _ForwardIterator last, _Compare comp) { if (first == last) return first; _ForwardIterator result = first; while (++first != last) if (comp(first, result)) result = first; return __result; }

/**

/**

template<typename _ForwardIterator, typename _Compare> _ForwardIterator max_element(_ForwardIterator first, _ForwardIterator last, _Compare comp) { if (first == last) return first; _ForwardIterator result = first; while (++first != last) if (comp(result, first)) result = first; return __result; }

/**

/**

_GLIBCXX_END_NAMESPACE_ALGO } // namespace std

endif / _STL_ALGO_H /