QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#734012 | #9569. Subway | ucup-team3646 | WA | 0ms | 3780kb | C++20 | 4.4kb | 2024-11-10 23:03:24 | 2024-11-10 23:03:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, l, r) for(ll i = l; i < r; i++)
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
/* ---- */
#define all(A) A.begin(), A.end()
#define elif else if
using pii = pair<ll, ll>;
bool chmin(auto &a, const auto &b) {return a > b ? a = b, 1 : 0;}
bool chmax(auto &a, const auto &b) {return a < b ? a = b, 1 : 0;}
struct IOSetup {
IOSetup() {
cin.tie(0);
ios::sync_with_stdio(0);
}
} iosetup;
template<class T>
void print(vector<T> a) {
for (auto x : a) cerr << x << ' ';
cerr << endl;
}
void print(auto x) {
cerr << x << endl;
}
template<class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
cerr << head << ' ';
print(forward<Tail>(tail)...);
}
struct Line {
ll a, b;
Line(ll a, ll b) : a(a), b(b){};
inline ll get(ll x) const { return a * x + b; }
inline bool over(const Line &b, const ll &x) { return get(x) < b.get(x); }
};
struct LCTree {
vll xs;
vector<Line> seg;
int sz;
ll inf = 1LL << 62;
LCTree(){};
LCTree(const vll &x) : xs(x) {
if (xs.size() == 0) xs = {0};
sort(xs.begin(), xs.end());
sz = 1;
while (sz < xs.size()) sz <<= 1;
while (xs.size() < sz) xs.push_back({xs.back() + 1});
seg.assign(2 * sz, Line(0, inf));
}
void upd(Line L, int k, int l, int r) {
while (true) {
int mid = (l + r) >> 1;
bool f = L.over(seg[k], xs[l]);
bool g = L.over(seg[k], xs[r - 1]);
if (f == g) {
if (f) swap(seg[k], L);
return;
}
bool mov = L.over(seg[k], xs[mid]);
if (mov) swap(seg[k], L);
if (f != mov) {
k = (k << 1), r = mid;
} else {
k = (k << 1) + 1, l = mid;
}
}
}
void add_line(ll a, ll b) {
Line L(a, b);
upd(L, 1, 0, sz);
}
// segment 用
void upd(Line L, int i) {
int ub = __bit_width(i) - 1;
int l = (sz >> ub) * (i - (1 << ub));
int r = l + (sz >> ub);
upd(L, i, l, r);
}
void add_segment(ll l, ll r, ll a, ll b) {
l = lower_bound(xs.begin(), xs.end(), l) - xs.begin() + sz;
r = lower_bound(xs.begin(), xs.end(), r) - xs.begin() + sz;
Line L(a, b);
for (; l < r; l >>= 1, r >>= 1) {
if (l & 1) upd(L, l++);
if (r & 1) upd(L, --r);
}
}
// segment 用ここまで
ll query(ll x) {
int k = lower_bound(xs.begin(), xs.end(), x) - xs.begin();
k += sz;
ll ret = seg[k].get(x);
while (k > 0) {
k = k >> 1;
ret = min(ret, seg[k].get(x));
}
return ret;
}
};
int main(){
int n,m;
cin>>n>>m;
vector<int>in_cost(m),out_cost(m);
rep(i,m){
cin>>in_cost[i];
}
rep(i,m){
cin>>out_cost[i];
}
map<pair<int,int>,int>dic;
vector<vector<pair<int,int>>>G(n);
vector<array<ll,4>>edges;
int ID=0;
rep(i,m){
int p;
cin>>p;
int frm;
cin>>frm;
frm--;
rep(j,p-1){
int d,to;
cin>>d>>to;
to--;
dic[{frm,i}]=ID;
edges.push_back({frm,to,i,d});
G[frm].push_back({in_cost[i],ID});
ID++;
frm=to;
}
}
vector<LCTree>LCT(n);
rep(i,n){
sort(G[i].rbegin(),G[i].rend());
vll xs;
for(auto [x,id]:G[i])xs.push_back(x);
LCT[i]=LCTree(xs);
}
ll inf=1LL<<62;
vector<ll>dp_v(n,inf),dp(ID,inf);
priority_queue<array<ll,2>,vector<array<ll,2>>,greater<array<ll,2>>>pq;
auto upd=[&](int v)->void{
if(G[v].size()==0)return;
auto [x,id]=G[v].back();
ll mn=LCT[v].query(x);
dp[id]=min(dp[id],mn);
pq.push({mn,id});
};
LCT[0].add_line(0,0);
upd(0);
dp_v[0]=0;
vi checked(ID,0);
while(!pq.empty()){
auto [mn,id]=pq.top();
auto [frm,to,t,d]=edges[id];
pq.pop();
dp_v[to]=min(dp_v[to],mn+d);
if(dp[id]!=mn)continue;
if(checked[id])continue;
checked[id]=1;
while(!G[frm].empty()){
int id2=G[frm].back().second;
if(checked[id2])G[frm].pop_back();
else break;
}
upd(frm);
ll len=mn+d;
dp_v[to]=min(dp_v[to],len);
LCT[to].add_line(out_cost[t],len);
upd(to);
if(dic.find({to,t})!=dic.end()){
int id2=dic[{to,t}];
dp[id2]=min(dp[id2],len);
pq.push({len,id2});
}
}
rep2(v,1,n){
cout<<dp_v[v]<<" \n"[v+1==n];
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3508kb
input:
6 3 1 5 1 5 5 1 3 1 2 2 3 3 3 5 1 2 1 4 3 3 4 5 4 6
output:
2 5 21 14 18
result:
ok 5 number(s): "2 5 21 14 18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
6 3 1 5 1 5 5 1 5 1 2 2 100 3 100 6 1 4 5 1 100 2 4 3 100 5 1 4 2 3 1 5
output:
2 31 43 37 136
result:
ok 5 number(s): "2 31 43 37 136"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
5 9 278281 70119 511791 834898 25300 63487 609134 236836 394497 835557 287345 579404 879128 636344 306393 569430 152565 47119 2 3 823004250 4 2 1 25427550 3 2 1 15849621 3 2 1 701911826 5 3 5 679672631 3 907176714 2 2 1 817370554 2 2 3 697987914 2 2 4 873900795 2 2 1 814305954 5
output:
817370554 15849621 80811085745 701911826
result:
ok 4 number(s): "817370554 15849621 80811085745 701911826"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
5 10 436148 103565 528276 212202 680282 92724 609031 560815 80390 406327 546832 581372 731920 348686 791433 98906 112247 118131 361076 724950 4 1 213029090 4 415633732 5 581145231 3 2 4 306227294 2 2 1 713116112 4 2 3 99672714 5 2 3 975143846 1 5 4 249118026 5 689334413 1 597093740 2 553624319 3 3 4...
output:
597093740 765908995 213029090 628662822
result:
ok 4 number(s): "597093740 765908995 213029090 628662822"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
3 5 696710 837216 390019 431068 960618 589388 829806 692481 154511 282620 2 1 711629163 3 2 1 781784306 3 2 1 686636041 3 2 3 794790206 2 2 1 844212542 2
output:
844212542 686636041
result:
ok 2 number(s): "844212542 686636041"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
3 8 344877 101098 328614 735002 476606 635558 573861 261083 964379 333960 25186 276560 258996 683650 765559 582374 2 3 838262394 1 2 2 863940316 3 2 2 476918371 3 3 3 320092619 1 400754003 2 3 3 150885055 2 90507792 1 2 3 190275693 2 2 2 600234969 3 2 2 679446528 3
output:
400754003 29224357199
result:
ok 2 number(s): "400754003 29224357199"
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3620kb
input:
50 52 895514 29433 851800 887860 340384 95967 506578 666268 850660 602220 717255 242039 34055 752012 248567 170469 505996 823344 143369 390858 112988 892365 15368 617804 351619 557340 788960 990487 283825 272924 24678 130649 341049 980236 558990 254726 682005 963825 953074 603477 706464 340694 23541...
output:
632126151 479346918 492618840 3695787776 22624579200 174047740 416387993526 21429733469 15831777447 203893499 522142321620 977566721 279122223 30345963113 804573598 73397618725 6389037892 224856032596 416404080694 75356833904 69909552850 4504114918 13173874327 1104455938 278587376156 270759151017 22...
result:
wrong answer 25th numbers differ - expected: '275720760247', found: '278587376156'