結果

問題 No.1012 荷物収集
ユーザー first_vilfirst_vil
提出日時 2020-03-20 22:02:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 4,156 bytes
コンパイル時間 1,828 ms
コンパイル使用メモリ 180,456 KB
実行使用メモリ 10,712 KB
最終ジャッジ日時 2023-08-21 16:37:17
合計ジャッジ時間 6,769 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 60 ms
10,712 KB
testcase_05 AC 61 ms
10,524 KB
testcase_06 AC 61 ms
9,996 KB
testcase_07 AC 63 ms
10,660 KB
testcase_08 AC 60 ms
9,908 KB
testcase_09 AC 61 ms
10,136 KB
testcase_10 AC 62 ms
9,776 KB
testcase_11 AC 62 ms
9,776 KB
testcase_12 AC 60 ms
10,372 KB
testcase_13 AC 60 ms
10,468 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 44 ms
6,380 KB
testcase_25 AC 57 ms
10,132 KB
testcase_26 AC 33 ms
6,260 KB
testcase_27 AC 8 ms
4,380 KB
testcase_28 AC 55 ms
9,732 KB
testcase_29 AC 33 ms
6,988 KB
testcase_30 AC 58 ms
9,600 KB
testcase_31 AC 25 ms
6,444 KB
testcase_32 AC 20 ms
4,816 KB
testcase_33 AC 30 ms
6,364 KB
testcase_34 AC 32 ms
6,988 KB
testcase_35 AC 50 ms
10,584 KB
testcase_36 AC 31 ms
6,268 KB
testcase_37 AC 31 ms
7,448 KB
testcase_38 AC 46 ms
6,700 KB
testcase_39 AC 21 ms
4,752 KB
testcase_40 AC 26 ms
6,264 KB
testcase_41 AC 63 ms
9,208 KB
testcase_42 AC 30 ms
7,560 KB
testcase_43 AC 41 ms
6,124 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
//#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

template<class T> class segtree {
    int n = 1;
    vector<T> dat;
    T def;

public:
    segtree() {}
    segtree(int _n, T _def) : def(_def) {
        while (n < _n)n *= 2;
        dat.resize(2 * n, def);
    }
    segtree(vector<T> a, T _def) : def(_def) {
        int _n = a.size();
        while (n < _n)n *= 2;
        dat.resize(2 * n, def);
        FOR(i, 0, _n)dat[i + n] = a[i];
        rFOR(i, 1, n)dat[i] = fun(dat[2 * i], dat[2 * i + 1]);
    }

    T fun(T x, T y) { return x + y; }

    void update(int i, T a) {
        i += n;
        chmin(dat[i], a);
        while (i > 1) {
            i /= 2;
            dat[i] = fun(dat[2 * i], dat[2 * i + 1]);
        }
    }

    T value(int l, int r) {
        l += n, r += n;

        T ret = def;
        for (; l < r; l /= 2, r /= 2) {
            if (l & 1) {
                ret = fun(ret, dat[l]);
                l++;
            }
            if (r & 1) {
                --r;
                ret = fun(ret, dat[r]);
            }
        }

        return ret;
    }

    T operator[](int k) { return dat[k + n]; }
};

int main() {
    init();

    int n, q; cin >> n >> q;
    vector<tuple<ll, ll, ll>> p;
    p.emplace_back(-1, 0, 0);
    FOR(i, 0, n) {
        ll x, w; cin >> x >> w;
        p.emplace_back(x, w, 0);
    }
    FOR(i, 0, q) {
        ll x; cin >> x;
        p.emplace_back(x, i, 1);
    }
    SORT(p);

    VL ans(q);
    ll l = 0, r = 0, lw = 0, rw = 0;
    FOR(i, 0, n + q + 1) {
        if (i == 0) {
            FOR(j, 0, n + q + 1) {
                ll x, w, t;
                tie(x, w, t) = p[j];
                if (t == 0) {
                    r += abs(get<0>(p[0]) - x) * w;
                    rw += w;
                }
            }
        }
        else {
            ll x, w, t;
            tie(x, w, t) = p[i];
            l += abs(get<0>(p[i - 1]) - x) * lw;
            r -= abs(get<0>(p[i - 1]) - x) * rw;
            if (t == 0) {
                lw += w;
                rw -= w;
            }
            else {
                ans[w] = l + r;
            }
        }
    }

    FOR(i, 0, q)cout << ans[i] << "\n";
}
0