Example #1
0
            void sift_down(Handle_type h)
            {
                auto curr = h;

                while (this->has_left_child(curr)) {
                    auto candidate = this->left_child(curr);
                    if (this->has_right_child(curr)) {
                        auto rc = this->right_child(curr);
                        candidate = cmp_(elem_[candidate], elem_[rc])?
                                        rc:
                                        candidate;
                    }

                    if (cmp_(elem_[candidate], elem_[curr])) {
                        break;
                    }
                    else {
                        // update
                        mstd::swap(elem_[curr], elem_[candidate]);
                        curr = candidate;
                    }
                }
            }
Example #2
0
static inline sub(num *a,num *b,num *c){
    if(a->sbit*b->sbit<0){
        add_(a,b,c);
        c->sbit=a->sbit;
    }else{
        int compare=cmp_(a,b);
        if(compare>0){
            sub_(a,b,c);
        }else{
            sub_(b,a,c);
        }
        c->sbit=compare*a->sbit;
    }
    rm0(c);
}
Example #3
0
            void sift_up(Handle_type h)
            {
                assert(h != this->root());

                auto curr = h;
                while (this->has_parent(curr)) {
                    const auto par = this->parent(curr);

                    if (cmp_(elem_[curr], elem_[par])) {
                        break;
                    }
                    else {
                        mstd::swap(elem_[par], elem_[curr]);

                        // update
                        curr = par;
                    }
                }
            }
PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
cmp(const Cntnr& r_c, const native_type& r_native_c, const std::string& r_call_fn)
{
  m_alloc.set_throw_prob(1);

  const size_t size = r_c.size();
  const size_t native_size = r_native_c.size();

  PB_DS_THROW_IF_FAILED(
			size == native_size,
			static_cast<unsigned long>(size) << " " <<
			static_cast<unsigned long>(native_size),
			& r_c,
			& r_native_c);

  const bool empty = r_c.empty();
  const bool native_empty = r_native_c.empty();

  PB_DS_THROW_IF_FAILED(
			empty == native_empty,
			empty << " " << native_empty,
			& r_c,
			& r_native_c);

  try
    {
      basic_cmp_(r_c, r_native_c);

      cmp_(r_c, r_native_c);
    }
  catch(...)
    {
      PB_DS_THROW_IF_FAILED(            false, "call-fn: " + r_call_fn, & r_c, & r_native_c);
    }
}
Example #5
0
int cmp(num *a,num *b){
    if(a->sbit*b->sbit<0) return CMP(a->sbit,b->sbit);
    return a->sbit*cmp_(a,b);
}
Example #6
0
int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    int a[kMaxN];
    int a_sorted[kMaxN];
    FindR fr[kMaxN];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        fr[i] = FindR(a[i], i);
        a_sorted[i] = a[i];
    }
    std::sort(a_sorted, a_sorted + n);
    int l[kMaxN];
    int u[kMaxN];
    int equal[kMaxA + 1];
    for (int i = 0; i < n; i++) {
        l[i] = std::lower_bound(a_sorted, a_sorted + n, a[i]) - a_sorted;
        u[i] = std::upper_bound(a_sorted, a_sorted + n, a[i]) - a_sorted - 1;
        equal[i] = std::numeric_limits<int>::min();
    }
    std::sort(fr, fr + n, FindRComparer());
    int r[kMaxN];
    int p[kMaxN];
    for (int i = 0; i < n; i++) {
        r[i] = fr[i].original_index();
        p[fr[i].original_index()] = i;
    }
    scanf("\n");
    int s[kMaxK];
    for (int i = 0; i < k; i++) {
        char c;
        scanf("%c ", &c);
        if (c == '<')
            s[i] = kGr;
        else if (c == '>')
            s[i] = kLo;
        else if (c == '=')
            s[i] = kEq;
    }
//    for (int i = 0; i < n; i++)
//        printf("a[%d] = %d  r=%d p=%d l=%d u=%d\n", i, a[i], r[i], p[i], l[i],
//                u[i]); 
    RangeTree<int> greater = RangeTree<int>(max_,
            std::numeric_limits<int>::min(), n);
    RangeTree<int> lower = RangeTree<int>(max_,
            std::numeric_limits<int>::min(), n);
    int position_best[kMaxN];
    for (int i = 0; i < n; i++) {
        int best = equal[a[i]]; 
        if (l[i] > 0)
            best = std::max(best, greater.GetValueOnInterval(0, l[i] - 1));
        if (u[i] < n - 1)
            best = std::max(best, lower.GetValueOnInterval(u[i] + 1, n - 1));
        if (best == std::numeric_limits<int>::min())
            best = 0;
        const int mod_best = best % k;
        ++best;
        position_best[i] = best;
        if (s[mod_best] == kGr)
            greater.UpdatePoint(p[i], best);
        else if (s[mod_best] == kLo)
            lower.UpdatePoint(p[i], best);
        else if (s[mod_best] == kEq)
            equal[a[i]] = std::max(equal[a[i]], best);
    }
    int total_best = std::numeric_limits<int>::min();
    for (int i = 0; i < n; i++)
        total_best = std::max(total_best, equal[a[i]]);
    total_best = std::max(total_best, greater.GetValueOnInterval(0, n - 1));
    total_best = std::max(total_best, lower.GetValueOnInterval(0, n - 1));
    printf("%d\n", total_best);
    int idx = n - 1;
    while (position_best[idx] != total_best)
        --idx;
//    for (int i = 0; i < n; i++)
//        printf("pb[%d]=%d\n", i, position_best[i]);
    int length_to_be_found = total_best - 1;
    bool used_in_final[kMaxN];
    used_in_final[idx] = true;
    while (length_to_be_found) {
        int last_value = a[idx];
        --idx;
        while (position_best[idx] != length_to_be_found || !cmp_(a[idx],
                    last_value, s[(length_to_be_found - 1) % k]))
            --idx;
        used_in_final[idx] = true;
        last_value = a[idx];
        --length_to_be_found;
    }
    for (int i = 0; i < n; i++)
        if (used_in_final[i])
            printf("%d ", a[i]);
    printf("\n");
//    for (int i = 0; i < 10; i++)
//        T.UpdatePoint(i, i);
//    T.PrintTree();
//    for (int i = 0; i < 5; i++)
//        printf("%d\n", T.GetValueOnInterval(i, 9 - i));
    return 0;
}
 bool operator() (const list_iterator_type &it1,
                  const list_iterator_type &it2) const {
   return cmp_(*it1, *it2);
 }
Example #8
0
bool PlainExpression::IsMatch(const FreqItem& freqitem) const {
    return cmp_(freqitem, key_index_, threshold_);
}