結果

問題 No.1012 荷物収集
ユーザー kcvlexkcvlex
提出日時 2020-03-20 22:12:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 3,686 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 182,892 KB
実行使用メモリ 11,848 KB
最終ジャッジ日時 2023-08-21 16:54:24
合計ジャッジ時間 7,433 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 50 ms
11,724 KB
testcase_05 AC 50 ms
11,672 KB
testcase_06 AC 50 ms
11,664 KB
testcase_07 AC 50 ms
11,740 KB
testcase_08 AC 50 ms
11,848 KB
testcase_09 AC 50 ms
11,664 KB
testcase_10 AC 51 ms
11,664 KB
testcase_11 AC 49 ms
11,672 KB
testcase_12 AC 50 ms
11,796 KB
testcase_13 AC 51 ms
11,752 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 47 ms
7,704 KB
testcase_25 AC 61 ms
9,552 KB
testcase_26 AC 32 ms
7,276 KB
testcase_27 AC 9 ms
4,376 KB
testcase_28 AC 58 ms
9,596 KB
testcase_29 AC 32 ms
7,780 KB
testcase_30 AC 60 ms
9,812 KB
testcase_31 AC 28 ms
5,604 KB
testcase_32 AC 22 ms
5,168 KB
testcase_33 AC 34 ms
6,832 KB
testcase_34 AC 38 ms
7,008 KB
testcase_35 AC 50 ms
8,756 KB
testcase_36 AC 35 ms
6,396 KB
testcase_37 AC 31 ms
7,448 KB
testcase_38 AC 49 ms
8,264 KB
testcase_39 AC 22 ms
5,668 KB
testcase_40 AC 26 ms
6,056 KB
testcase_41 AC 66 ms
10,344 KB
testcase_42 AC 32 ms
6,456 KB
testcase_43 AC 43 ms
7,968 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); }
template <typename T, std::size_t Head, std::size_t ...Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t ...Args> using mdarray = typename multi_dem_array<T, Args...>::type;
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }

int main() {
    ll n, q;
    std::cin >> n >> q;
    vec<pll> xw(n);
    vec<ll> xv(q);
    for (auto &&e : xw) {
        ll x, w;
        std::cin >> x >> w;
        e = pll(x, w);
    }
    for (ll &e : xv) std::cin >> e;
    vec<ll> ord(q);
    std::iota(ALL(ord), 0);
    std::sort(ALL(ord), [&](ll i, ll j) { return xv[i] < xv[j]; });
    std::sort(ALL(xw));
    std::sort(ALL(xv));
    vec<ll> ans1(q), ans2(q);
    std::queue<pll> qf, qb;
    for (ll i = 0; i < n; i++) {
        qf.push(xw[i]);
        qb.push(xw[n - 1 - i]);
    }

    {
        ll sum = 0 , pre = 0;
        for (ll i = 0; i < q; i++) {
            ll x = xv[i];
            if (i) ans1[i] += ans1[i - 1];
            ans1[i] += (x - pre) * sum;
            pre = x;
            while (qf.size()) {
                ll xf, w;
                std::tie(xf, w) = qf.front();
                if (x < xf) break;
                qf.pop();
                sum += w;
                ans1[i] += (x - xf) * w;
            }
        }
    }


    {
        ll sum = 0, pre = 0;
        for (ll i = q - 1; 0 <= i; i--) {
            ll x = xv[i];
            if (i + 1 < q) ans2[i] += ans2[i + 1];
            ans2[i] += (pre - x) * sum;
            pre = x;
            while (qb.size()) {
                ll xb, w;
                std::tie(xb, w) = qb.front();
                if (xb < x) break;
                qb.pop();
                sum += w;
                ans2[i] += (xb - x) * w;
            }
        }

    }

    vec<ll> ans(q);
    for (ll i = 0; i < q; i++) {
        ll idx = ord[i];
        ans[idx] = ans1[i] + ans2[i];
    }

    for (ll e : ans) std::cout << e << '\n';
    return 0;
}
0