結果
問題 |
No.1012 荷物収集
|
ユーザー |
![]() |
提出日時 | 2020-03-20 21:50:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 201 ms / 2,000 ms |
コード長 | 1,135 bytes |
コンパイル時間 | 2,607 ms |
コンパイル使用メモリ | 202,932 KB |
最終ジャッジ日時 | 2025-01-09 08:30:28 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:18:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf("%lld %lld",&V[i].first,&V[i].second); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:49:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 49 | scanf("%lld",&P.first); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000000 int main(){ int N,Q; cin>>N>>Q; vector<pair<long long,long long>> V(N); for(int i=0;i<N;i++){ scanf("%lld %lld",&V[i].first,&V[i].second); } V.emplace_back(-1,0); V.emplace_back(1000000001,0); sort(V.begin(),V.end()); vector<long long> dis(V.size(),0); vector<long long> LL(V.size()),RR(V.size()); long long L = 0,R = 0; for(int i=0;i<V.size();i++){ dis[0] += abs(V[0].first - V[i].first)*V[i].second; R += V[i].second; } LL[0] = L; RR[0] = R; for(int i=1;i<dis.size();i++){ long long D = V[i].first-V[i-1].first; dis[i] = dis[i-1] + D*(L-R); L += V[i].second; R -= V[i].second; LL[i] = L; RR[i] = R; } for(int i=0;i<Q;i++){ pair<long long,long long> P(0,1000000001); scanf("%lld",&P.first); auto it = upper_bound(V.begin(),V.end(),P); it--; int ind = distance(V.begin(),it); long long ans = dis[ind]; ans += (P.first-V[ind].first)*(LL[ind]-RR[ind]); cout<<ans<<endl; } return 0; }