結果

問題 No.1012 荷物収集
ユーザー rxoxixyxdrxoxixyxd
提出日時 2020-03-20 23:15:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,917 bytes
コンパイル時間 1,904 ms
コンパイル使用メモリ 180,320 KB
実行使用メモリ 29,852 KB
最終ジャッジ日時 2023-08-21 22:29:23
合計ジャッジ時間 17,334 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 450 ms
29,844 KB
testcase_05 AC 451 ms
29,660 KB
testcase_06 AC 452 ms
29,676 KB
testcase_07 AC 448 ms
29,648 KB
testcase_08 AC 450 ms
29,852 KB
testcase_09 AC 450 ms
29,796 KB
testcase_10 AC 451 ms
29,780 KB
testcase_11 AC 453 ms
29,700 KB
testcase_12 AC 449 ms
29,776 KB
testcase_13 AC 451 ms
29,720 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>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

typedef long long ll;

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 = 1e9;
const long long INFL = 1LL<<60;


int main()
{
  int n, q;
  cin >> n >> q;

  vector<ll> x(n);
  vector<ll> w(n);
  rep(i, n) {
    cin >> x[i] >> w[i];
  }

  ll sum_w = SUM(w);

  map<ll, ll> mp_l;
  map<ll, ll> mp_r;
  map<ll, ll> mp_lw;
  map<ll, ll> mp_rw;
  for (int i = 0; i < n; i++) {
    ll cost = 0;
    ll weight = 0;
    if (i > 0) {
      cost += mp_l[x[i-1]];
      weight += mp_lw[x[i-1]];
      cost += abs(x[i-1] - x[i]) * weight;
    }
    weight += w[i];
    mp_l[x[i]] = cost;
    mp_lw[x[i]] = weight;
  }
  for (int i = n-1; i >= 0; i--) {
    ll cost = 0;
    ll weight = 0;
    if (i < n-1) {
      cost += mp_r[x[i+1]];
      weight += mp_rw[x[i+1]];
      cost += abs(x[i+1] - x[i]) * weight;
    }
    weight += w[i];
    mp_r[x[i]] = cost;
    mp_rw[x[i]] = weight;
  }

  sort(ALL(x));

  rep(i, q) {
    ll target;
    cin >> target;
    // 1番近い xi を求める
    auto itr1 = lower_bound(ALL(x), target);
    if (itr1 != x.begin() || itr1 == x.end()) itr1--;
    auto itr2 = upper_bound(ALL(x), target);
    if (itr2 == x.end()) itr2--;
    ll ans = 0;
    if (*itr1 < target) {
      ans += mp_l[*itr1] + abs(*itr1 - target) * mp_lw[*itr1];
    }
    if (*itr2 > target) {
      ans += mp_r[*itr2] + abs(*itr2 - target) * mp_rw[*itr2];
    }
    cout << ans << endl;
  }

  return 0;
}
0