結果

問題 No.1012 荷物収集
ユーザー T1610T1610
提出日時 2020-03-20 22:15:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,849 bytes
コンパイル時間 1,987 ms
コンパイル使用メモリ 184,680 KB
実行使用メモリ 19,840 KB
最終ジャッジ日時 2024-05-08 22:23:05
合計ジャッジ時間 8,010 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 146 ms
19,588 KB
testcase_05 AC 150 ms
19,712 KB
testcase_06 AC 150 ms
19,580 KB
testcase_07 AC 148 ms
19,712 KB
testcase_08 AC 148 ms
19,728 KB
testcase_09 AC 144 ms
19,840 KB
testcase_10 AC 150 ms
19,712 KB
testcase_11 AC 149 ms
19,708 KB
testcase_12 AC 146 ms
19,712 KB
testcase_13 AC 149 ms
19,712 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
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    vl x(N), w(N);
    {   
        vector<pll> p(N);
        rep(i, N) cin >> p[i].fi >> p[i].se;
        sort(all(p));
        rep(i, N) {
            x[i] = p[i].fi;
            w[i] = p[i].se;
        }
    }
    vl X(Q);
    rep(i, Q) cin >> X[i];
    sort(all(X));

    map<ll, ll> mp;
    {
        rep(i, N) mp[x[i]] = 0;
        rep(i, Q) mp[X[i]] = 0;
        int cnt = 0;
        for(auto& p : mp) p.se = cnt++;
    }
    ll add = 0LL;
    vector<ll> ans(mp.size());
    auto cur = mp.begin();
    {
        rep(i, N) {
            ans[0] += w[i] * (x[i] - cur->fi);
            dump(i);dump(w[i]);dump(x[i]);dump(cur->fi);dumpL(w[i] * (x[i] - cur->fi));
            if(x[i] == cur->fi) add += w[i];
            else add -=w[i];
        }
        
    }
    dumpVL(mp);
    dumpL(add);
    ++cur;
    auto pre = mp.begin();
    {
        while(cur != mp.end()) {
            ll d = cur->fi - pre->fi;
            ans[cur->se] = ans[pre->se] + add * d;
            auto i = lower_bound(all(x), cur->fi) - x.begin();
            if(i < (int)x.size() && x[i] == cur->fi) {
                add += w[i] * 2;
            }
            ++cur;
            ++pre;
        }
    }
    rep(i, Q) {
        cout << ans[mp[X[i]]] << '\n';
    }
    dumpVL(ans);
    return 0;
}
0