結果

問題 No.1012 荷物収集
ユーザー snow39snow39
提出日時 2020-03-20 21:54:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 1,047 ms
コンパイル使用メモリ 101,632 KB
実行使用メモリ 7,240 KB
最終ジャッジ日時 2023-08-21 16:21:07
合計ジャッジ時間 5,979 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 46 ms
7,064 KB
testcase_05 AC 46 ms
7,028 KB
testcase_06 AC 47 ms
6,996 KB
testcase_07 AC 46 ms
6,964 KB
testcase_08 AC 47 ms
7,240 KB
testcase_09 AC 46 ms
6,964 KB
testcase_10 AC 46 ms
7,164 KB
testcase_11 AC 46 ms
7,084 KB
testcase_12 AC 46 ms
6,928 KB
testcase_13 AC 47 ms
7,048 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 43 ms
5,464 KB
testcase_25 AC 57 ms
6,160 KB
testcase_26 AC 31 ms
4,856 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 56 ms
6,284 KB
testcase_29 AC 33 ms
5,224 KB
testcase_30 AC 57 ms
6,236 KB
testcase_31 AC 25 ms
4,408 KB
testcase_32 AC 19 ms
4,384 KB
testcase_33 AC 30 ms
4,628 KB
testcase_34 AC 33 ms
5,020 KB
testcase_35 AC 47 ms
5,600 KB
testcase_36 AC 30 ms
4,592 KB
testcase_37 AC 31 ms
4,884 KB
testcase_38 AC 45 ms
5,596 KB
testcase_39 AC 20 ms
4,384 KB
testcase_40 AC 25 ms
4,408 KB
testcase_41 AC 63 ms
6,452 KB
testcase_42 AC 31 ms
4,872 KB
testcase_43 AC 41 ms
5,368 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N,Q;
  cin>>N>>Q;
  vector<ll> X(N),W(N);
  rep(i,N) cin>>X[i]>>W[i];
  vector<ll> Y(Q);
  rep(i,Q) cin>>Y[i];

  vector<int> ord(N);
  rep(i,N) ord[i]=i;
  sort(ord.begin(),ord.end(),[&](int a,int b){
    return X[a]<X[b];
  });

  vector<int> query(Q);
  rep(i,Q) query[i]=i;
  sort(query.begin(),query.end(),[&](int a,int b){
    return Y[a]<Y[b];
  });


  vector<ll> ans(Q,0);
  ll weg=0;
  int now=0;
  ll sum=0;
  for(int i=0;i<Q;i++){
    int q=query[i];
    ll res=0;
    if(i>0) res=(Y[q]-Y[query[i-1]])*weg;
    while(now<N&&X[ord[now]]<=Y[q]){
      int tar=ord[now];
      res+=(Y[q]-X[tar])*W[tar];
      weg+=W[tar];
      now++;
    }
    ans[q]+=sum+res;
    sum+=res;
  }

  weg=0;
  now=N-1;
  sum=0;
  for(int i=Q-1;i>=0;i--){
    int q=query[i];
    ll res=0;
    if(i<Q-1) res=(Y[query[i+1]]-Y[q])*weg;
    while(now>=0&&X[ord[now]]>=Y[q]){
      int tar=ord[now];
      res+=(X[tar]-Y[q])*W[tar];
      weg+=W[tar];
      now--;
    }
    ans[q]+=sum+res;
    sum+=res;
  }

  rep(i,Q) cout<<ans[i]<<"\n";

  return 0;
}
0