結果

問題 No.1012 荷物収集
ユーザー jjjjjjjtgpptmjjjjjjjjjtgpptmjj
提出日時 2020-03-20 23:07:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,765 bytes
コンパイル時間 2,711 ms
コンパイル使用メモリ 175,956 KB
実行使用メモリ 8,716 KB
最終ジャッジ日時 2023-08-21 18:38:58
合計ジャッジ時間 9,389 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 174 ms
8,528 KB
testcase_05 AC 171 ms
8,488 KB
testcase_06 AC 175 ms
8,564 KB
testcase_07 AC 173 ms
8,660 KB
testcase_08 AC 173 ms
8,716 KB
testcase_09 AC 176 ms
8,616 KB
testcase_10 AC 174 ms
8,620 KB
testcase_11 AC 172 ms
8,504 KB
testcase_12 AC 171 ms
8,500 KB
testcase_13 AC 169 ms
8,500 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, Q;
    cin >> N >> Q;
    vec<ll> x(N), w(N);
    vec<pair<ll, ll>> xw(N);
    rep(i,N){
        cin >> xw[i].first >> xw[i].second;
    }
    sort(all(xw));
    rep(i,N){
        x[i] = xw[i].first;
        w[i] = xw[i].second;
    }
    vec<ll> xq(Q);
    rep(i,Q){
        cin >> xq[i];
    }
    sort(all(xq));
    //print(x);print(w);print(xq);
    vec<ll> cumw(N+1, 0);
    rep(i,N)cumw[i+1] = cumw[i] + w[i];
    //print(cumw);
    //x[i]にいるときにかかる合計のコスト
    vec<ll> cost(N, 0);
    rep(i,N){
        cost[0] += abs(x[0] - x[i]) * w[i]; 
    }
    rep1(i,N){
        cost[i] = cost[i-1];
        //[0, i)
        ll lsum = cumw[i] - cumw[0];
        //[i+1, N)
        ll rsum = cumw[N] - cumw[i];
        //cerr << lsum << " " <<  rsum << endl;
        cost[i] -= abs(x[i-1] - x[i]) * rsum;
        cost[i] += abs(x[i-1] - x[i]) * lsum;
    }
    //print(cost);
    rep(i,Q){
        int idx = lower_bound(all(x), xq[i]) - x.begin();
        //x[idx-1]より大きい、x[idx]以下
        //dump(idx);
        /*
        if(x[idx] == xq[i]){
            cout << cost[idx] << endl;
            continue;
        }
        */
        ll ans = cost[idx];
        if(idx == N){
            ans += cumw[idx] * abs(x[N-1] - xq[i]);
            cout << ans << endl;
            continue;
        }
        
        ll diff = abs(x[idx] - xq[i]);
        //[0, idx)
        ll lsum = cumw[idx] - cumw[0];
        //[idx, N)
        ll rsum = cumw[N] - cumw[idx];
        ans += diff * rsum;
        ans -= diff * lsum;
        cout << ans << endl;
    }
}
0