結果

問題 No.1012 荷物収集
ユーザー T1610T1610
提出日時 2020-03-20 22:18:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 2,715 bytes
コンパイル時間 1,895 ms
コンパイル使用メモリ 179,896 KB
実行使用メモリ 19,636 KB
最終ジャッジ日時 2023-08-21 17:01:39
合計ジャッジ時間 8,847 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 149 ms
19,456 KB
testcase_05 AC 149 ms
19,580 KB
testcase_06 AC 147 ms
19,560 KB
testcase_07 AC 147 ms
19,452 KB
testcase_08 AC 147 ms
19,568 KB
testcase_09 AC 146 ms
19,532 KB
testcase_10 AC 146 ms
19,580 KB
testcase_11 AC 147 ms
19,512 KB
testcase_12 AC 147 ms
19,452 KB
testcase_13 AC 148 ms
19,636 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 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,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 139 ms
13,168 KB
testcase_25 AC 209 ms
16,652 KB
testcase_26 AC 81 ms
10,548 KB
testcase_27 AC 16 ms
4,936 KB
testcase_28 AC 202 ms
16,280 KB
testcase_29 AC 74 ms
11,492 KB
testcase_30 AC 184 ms
16,796 KB
testcase_31 AC 69 ms
8,360 KB
testcase_32 AC 53 ms
7,568 KB
testcase_33 AC 91 ms
10,020 KB
testcase_34 AC 100 ms
10,444 KB
testcase_35 AC 157 ms
14,380 KB
testcase_36 AC 98 ms
9,972 KB
testcase_37 AC 69 ms
11,284 KB
testcase_38 AC 162 ms
13,556 KB
testcase_39 AC 54 ms
7,928 KB
testcase_40 AC 70 ms
8,620 KB
testcase_41 AC 230 ms
17,852 KB
testcase_42 AC 98 ms
10,348 KB
testcase_43 AC 136 ms
12,924 KB
testcase_44 AC 2 ms
4,380 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);
            if(x[i] == cur->fi) add += w[i];
            else add -=w[i];
        }
        
    }
    ++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';
    }
    return 0;
}
0