Esempio n. 1
0
    ll area_of_union(const vector<rect>& rects) {
        vi y_vals;
        for (auto& rect : rects) {
            y_vals.push_back(rect.y1);
            y_vals.push_back(rect.y2);
        }
        sort(all(y_vals));
        y_vals.erase(unique(all(y_vals)), y_vals.end());

        seg_tree_lazy<y_interval, update_ct> st(y_vals.size() - 1, false);
        for (int i = 0; i + 1 < y_vals.size(); i++)
            st.value[st.S + i] = y_interval(y_vals[i+1] - y_vals[i]);
        st.rebuild();

        vector<v_boundary> events;
        for (auto &rect : rects) {
            int y1i = lower_bound(all(y_vals), rect.y1) - y_vals.begin();
            int y2i = lower_bound(all(y_vals), rect.y2) - y_vals.begin();
            events.push_back({ rect.x1,  1, y1i, y2i - 1 });
            events.push_back({ rect.x2, -1, y1i, y2i - 1 });
        }
        sort(all(events));

        ll ans = 0;
        for (int e = 0; e < events.size(); e++) {
            if (e) ans += (events[e].x - events[e-1].x) * 1ll * st.query(0, y_vals.size() - 2).cover;
            st.upd(events[e].y1i, events[e].y2i, update_ct(events[e].sign));
        }
        return ans;
    }
Esempio n. 2
0
static void update_mode_probs(int n_modes,
                              const vp9_tree_index *tree, unsigned int *cnt,
                              vp9_prob *pre_probs, vp9_prob *dst_probs,
                              unsigned int tok0_offset) {
#define MAX_PROBS 32
  vp9_prob probs[MAX_PROBS];
  unsigned int branch_ct[MAX_PROBS][2];
  int t;

  assert(n_modes - 1 < MAX_PROBS);
  vp9_tree_probs_from_distribution(tree, probs, branch_ct, cnt, tok0_offset);
  for (t = 0; t < n_modes - 1; ++t)
    dst_probs[t] = update_ct(pre_probs[t], probs[t], branch_ct[t]);
}
Esempio n. 3
0
 update_ct operator + (const update_ct& o) const {
     return update_ct(ct + o.ct);
 }