QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#246703#7523. Partially Free MealikefumyCompile Error//C++206.3kb2023-11-11 01:01:272023-11-11 01:01:28

Judging History

你现在查看的是最新测评结果

  • [2023-11-11 01:01:28]
  • 评测
  • [2023-11-11 01:01:27]
  • 提交

answer

#include<bits/stdc++.h>
#include<atcoder/segtree>
using namespace std;
using namespace atcoder;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
    if(x > y) {
        x = y;
        return true;
    } else return false;
}
template<class T> bool chmax(T& x, T y){
    if(x < y) {
        x = y;
        return true;
    } else return false;
}

// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )

#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )

#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)

// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)

// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)

// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)    
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c)

// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = b - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = b - 1; i >= (ll)(a); i -= c)

// for_earh
#define fore(e, v) for (auto&& e : v)

// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

template<class T, T(* op)(T, T), T(* e)()>
struct segment_tree {
private:
    int n, tn;
    vector<T> node;

public:
    segment_tree(int _n, vector<T> a = {}) : tn(_n) {
        n = 1;
        while (n < _n) n *= 2;

        node.resize(2 * n, e());
        if (!a.empty()) {
            for (int i = 0; i < (int)a.size(); i++) {
                update(i, a[i]);
            }
        }
    }

    void update(int i, T val) {
        i += n;
        node[i] = val;
        while (i / 2) {
            i /= 2;
            node[i] = op(node[i * 2], node[i * 2 + 1]);
        }
    }

    T get_val(int l, int r) {
        l += n;
        r += n;
        
        T lval = e(), rval = e();
        while (l < r) {
            if (l & 1) lval = op(lval, node[l++]);
            if (r & 1) rval = op(node[--r], rval);
            l /= 2, r /= 2;
        }

        return op(lval, rval);
    }

    template<class F>
    int right_search(int i, F f) {
        int ret = i, len = 1;
        i += n;
        T val = e();
        while (ret < n) {
            if (i & 1) {
                if (!f(op(val, node[i]))) break;
                val = op(val, node[i]);
                ret += len;
                i++;
            }
            len *= 2, i /= 2;
        }

        if (ret == n) return tn;

        while (len > 1) {
            len /= 2, i *= 2;
            if (f(op(val, node[i]))) {
                val = op(val, node[i]);
                ret += len;
                i++;
            }
        }

        return min(ret, tn);
    }

    template<class F>
    int left_search(int i, F f) {
        int ret = i, len = 1;
        i += n;
        T val = e();
        while (ret > 0) {
            if (i & 1) {
                i--;
                if (!f(op(node[i], val))) break;
                val = op(node[i], val);
                ret -= len;
            }
            len *= 2, i /= 2;
        }

        if (ret == 0) return 0;

        while (len > 1) {
            len /= 2, i = i * 2 + 1;
            if (f(op(node[i], val))) {
                val = op(node[i], val);
                ret -= len;
                i--;
            }
        }

        return ret;
    }
};

int n;
int l[200010], r[200010], lb[200010], ub[200010], anum[200010];
ll ans[200010], idx[200010];

pil op(pil a, pil b) {
    return {a.first + b.first, a.second + b.second};
}

pil e() {
    return {0, 0};
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> n;
    vector<pii> m;
    vector<int> as;
    rep (i, 1, n + 1) {
        ll a, b;
        cin >> a >> b;
        m.push_back({b, a});
        as.push_back(a);
        r[i] = n, ans[i] = linf;
    }

    sort(all(m));
    sort(all(as));
    map<int, int> cnt;
    rep (i, n) {
        anum[i] = lower_bound(all(as), m[i].second) - as.begin() + cnt[m[i].second]++;
    }

    vector<int> q = {(n + 2) / 2};
    lb[(n + 2) / 2] = 1, ub[(n + 2) / 2] = n + 1;
    while (!q.empty()) {
        vector<int> nq;
        segment_tree<pil, op, e> st(n);
        int prei = 0;
        fore (k, q) {
            rep (i, min(l[k], prei), r[k]) {
                auto [b, a] = m[i];
                if (prei <= i) st.update(anum[i], {1, a});
                if (i + 1 < k) continue;
                int it = st.right_search(0, [&](pil p) {
                    return p.first <= k;
                });
                ll mnsum = st.get_val(0, it).second;
                if (ans[k] >= mnsum + b) ans[k] = mnsum + b, idx[k] = i;
            }

            auto update = [&](int x, int y, int nl, int nr) -> void {
                if (x == y) return;
                int mid = (x + y) / 2;
                lb[mid] = x, ub[mid] = y, l[mid] = nl, r[mid] = nr;
                nq.push_back(mid);
            };

            prei = r[k];
            update(lb[k], k, l[k], idx[k] + 1);
            update(k + 1, ub[k], idx[k], r[k]);
        }
        q = nq;
    }

    rep (i, 1, n + 1) {
        cout << ans[i] << '\n';
    }
}

Details

answer.code:2:9: fatal error: atcoder/segtree: No such file or directory
    2 | #include<atcoder/segtree>
      |         ^~~~~~~~~~~~~~~~~
compilation terminated.