#include "walk.h"
#include<bits/stdc++.h>
using namespace std;
const long long maxn=100000+10,kaf=1e9+5,inf=1e18+5;
long long n,allx[maxn],q,allh[maxn];
vector<long long>addq[maxn],delq[maxn];
struct qu{
long long l,r,res,y;
}allq[maxn];
struct segment{
struct node{
long long mina,cl,cr;
set<pair<long long,long long>>st;
node(){
mina=inf;
cl=cr=-1;
st.insert(make_pair(inf,-1));
}
}fakenode;
vector<node>seg;
segment(){
seg.resize(2);
}
long long getl(long long i){
if(seg[i].cl==-1){
seg.push_back(fakenode);
seg[i].cl=(long long)seg.size()-1;
}
return seg[i].cl;
}
long long getr(long long i){
if(seg[i].cr==-1){
seg.push_back(fakenode);
seg[i].cr=(long long)seg.size()-1;
}
return seg[i].cr;
}
void upd(long long i,long long l,long long r,long long tl,long long tr,pair<long long,long long> w){
//cout<<"upd: "<<l<<" "<<r<<" "<<tl<<" "<<tr<<" "<<i<<endl;
if(l>r||l>tr||r<tl||tl>tr){
return ;
}
if(l>=tl&&r<=tr){
seg[i].st.insert(w);
seg[i].mina=(*seg[i].st.begin()).first;
return ;
}
long long m=(l+r)>>1;
upd(getl(i),l,m,tl,tr,w);
upd(getr(i),m+1,r,tl,tr,w);
seg[i].mina=min(seg[getl(i)].mina,seg[getr(i)].mina);
}
void erase(long long i,long long l,long long r,long long tl,long long tr,pair<long long,long long> w){
if(l>r||l>tr||r<tl||tl>tr){
return ;
}
if(l>=tl&&r<=tr){
seg[i].st.erase(w);
seg[i].mina=(*seg[i].st.begin()).first;
return ;
}
long long m=(l+r)>>1;
erase(getl(i),l,m,tl,tr,w);
erase(getr(i),m+1,r,tl,tr,w);
seg[i].mina=min(seg[getl(i)].mina,seg[getr(i)].mina);
}
long long pors(long long i,long long l,long long r,long long tl,long long tr){
if(l>r||l>tr||r<tl||tl>tr||i==-1){
return inf;
}
if(l>=tl&&r<=tr){
return seg[i].mina;
}
long long m=(l+r)>>1;
return min(pors(seg[i].cl,l,m,tl,tr),pors(seg[i].cr,m+1,r,tl,tr));
}
}segmanf,segmos;
long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y,int s, int g) {
n=x.size();
q=(long long)l.size();
for(long long i=0;i<n;i++){
allx[i]=x[i];
allh[i]=h[i];
}
if(s!=0||g!=n-1){
exit(23);
return 0;
}
for(long long i=0;i<q;i++){
allq[i].l=l[i];
allq[i].r=r[i];
allq[i].y=y[i];
addq[l[i]].push_back(i);
delq[r[i]].push_back(i);
}
long long mainres=inf;
int cnt=0;
if(n==1){
return 0;
}
for(long long i=0;i<n;i++){
if(i==n-1){
mainres=segmos.pors(1,0,kaf-1,0,kaf-1)+allx[i];
}
for(auto x:addq[i]){
if(i==0){
allq[x].res=allq[x].y;
}else{
allq[x].res=min(segmanf.pors(1,0,kaf-1,0,allq[x].y)+allq[x].y,segmos.pors(1,0,kaf-1,allq[x].y,allh[i])-allq[x].y)+allx[i];
}
segmos.upd(1,0,kaf-1,allq[x].y,allq[x].y,make_pair(allq[x].res-allx[i]+allq[x].y,x));
segmanf.upd(1,0,kaf-1,allq[x].y,allq[x].y,make_pair(allq[x].res-allx[i]-allq[x].y,x));
cnt++;
}
for(auto x:delq[i]){
segmos.erase(1,0,kaf-1,allq[x].y,allq[x].y,make_pair(allq[x].res-allx[allq[x].l]+allq[x].y,x));
segmanf.erase(1,0,kaf-1,allq[x].y,allq[x].y,make_pair(allq[x].res-allx[allq[x].l]-allq[x].y,x));
cnt--;
}
if(i!=n-1&&cnt==0){
return -1;
}
}
if(mainres>=inf){
mainres=-1;
}
return mainres;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
4956 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
4952 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
10332 KB |
Output is correct |
2 |
Correct |
1483 ms |
725872 KB |
Output is correct |
3 |
Correct |
1428 ms |
722096 KB |
Output is correct |
4 |
Correct |
1376 ms |
728036 KB |
Output is correct |
5 |
Correct |
1431 ms |
736196 KB |
Output is correct |
6 |
Correct |
1376 ms |
733240 KB |
Output is correct |
7 |
Correct |
598 ms |
375000 KB |
Output is correct |
8 |
Correct |
1113 ms |
729292 KB |
Output is correct |
9 |
Correct |
1487 ms |
734948 KB |
Output is correct |
10 |
Correct |
272 ms |
53968 KB |
Output is correct |
11 |
Correct |
11 ms |
7516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
10332 KB |
Output is correct |
2 |
Correct |
1483 ms |
725872 KB |
Output is correct |
3 |
Correct |
1428 ms |
722096 KB |
Output is correct |
4 |
Correct |
1376 ms |
728036 KB |
Output is correct |
5 |
Correct |
1431 ms |
736196 KB |
Output is correct |
6 |
Correct |
1376 ms |
733240 KB |
Output is correct |
7 |
Correct |
598 ms |
375000 KB |
Output is correct |
8 |
Correct |
1113 ms |
729292 KB |
Output is correct |
9 |
Correct |
1487 ms |
734948 KB |
Output is correct |
10 |
Correct |
272 ms |
53968 KB |
Output is correct |
11 |
Correct |
11 ms |
7516 KB |
Output is correct |
12 |
Correct |
1552 ms |
723088 KB |
Output is correct |
13 |
Correct |
59 ms |
21936 KB |
Output is correct |
14 |
Correct |
1436 ms |
737456 KB |
Output is correct |
15 |
Correct |
612 ms |
287484 KB |
Output is correct |
16 |
Correct |
732 ms |
280820 KB |
Output is correct |
17 |
Correct |
606 ms |
280792 KB |
Output is correct |
18 |
Correct |
608 ms |
287484 KB |
Output is correct |
19 |
Correct |
603 ms |
280916 KB |
Output is correct |
20 |
Correct |
711 ms |
370016 KB |
Output is correct |
21 |
Correct |
29 ms |
21312 KB |
Output is correct |
22 |
Correct |
821 ms |
521092 KB |
Output is correct |
23 |
Correct |
789 ms |
530136 KB |
Output is correct |
24 |
Correct |
859 ms |
575448 KB |
Output is correct |
25 |
Correct |
1012 ms |
725748 KB |
Output is correct |
26 |
Correct |
1103 ms |
729556 KB |
Output is correct |
27 |
Correct |
1414 ms |
736688 KB |
Output is correct |
28 |
Correct |
48 ms |
21916 KB |
Output is correct |
29 |
Correct |
1406 ms |
732864 KB |
Output is correct |
30 |
Correct |
617 ms |
375752 KB |
Output is correct |
31 |
Correct |
1371 ms |
734828 KB |
Output is correct |
32 |
Correct |
215 ms |
37176 KB |
Output is correct |
33 |
Incorrect |
204 ms |
38452 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
4956 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |