#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define pb push_back
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define F first
#define S second
#define ET cout << "\n"
#define MP make_pair
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF=1e18;
/*
j<i
si-sj+di+dj>k
si+di-k>sj-dj
x-y<0
|sj-x|+|si-y|+di+dj+c<=k
x+y>=(sj+dj)+(si+di)-k+c ->b0
x-y>=(sj+dj)-(si-di)-k+c ->b1
x-y<=(sj-dj)-(si+di)+k-c ->b2
x+y<=(sj-dj)+(si-di)+k-c ->b3
y>=b0-x
y>=x-b2
y<=x-b1
y<=b3-x
y<=sn
*/
ll bit[1000005];
vector<ll> vec;
void modify(ll x,ll v)
{
for(;x<=vec.size();x+=x&-x) bit[x]=max(bit[x],v);
}
ll query(ll x)
{
ll re;
for(re=-INF;x;x-=x&-x) re=max(re,bit[x]);
return re;
}
ll find_shortcut(int n,vector<int> l,vector<int> d, int c)
{
ll mx=-INF,L=1,R=0;
vector<ll> s(n,0),dp(n,0),idx(n,0);
for(int i=1;i<n;++i)
s[i]=s[i-1]+l[i-1];
for(int i=0;i<n;++i)
dp[i]=max((ll)d[i],s[i]+mx),mx=max(mx,dp[i]-s[i]);
for(int i=1;i<n;++i)
R=max(R,dp[i-1]+d[i]+s[i]-s[i-1]);
for(int i=0;i<n;++i)
vec.pb(s[i]-d[i]);
sort(ALL(vec)),vec.resize(unique(ALL(vec))-vec.begin());
for(int i=1;i<=vec.size();++i)
bit[i]=-INF;
for(int i=0;i<n;++i)
idx[i]=upper_bound(ALL(vec),s[i]-d[i])-vec.begin(),modify(idx[i],s[i]+d[i]);
while(L<R)
{
ll mid=L+R>>1,mit=INF,b0=-INF,b1=-INF,b2=-1,b3=INF,flag=0;
for(int i=1;i<n;++i)
{
mit=min(mit,s[i-1]-d[i-1]);
ll p=lower_bound(ALL(vec),s[i]+d[i]-mid)-vec.begin(),mx=query(p),mi=mit<s[i]+d[i]-mid?mit:INF;
b0=max(b0,s[i]+d[i]+mx-mid+c),b1=max(b1,mx-s[i]+d[i]-mid+c);
b2=min(b2,mi-s[i]-d[i]+mid-c),b3=min(b3,mi+s[i]-d[i]+mid-c);
}
for(int i=0,j=n,k=0;i+1<n&&!flag;++i)
{
ll up=min({s[n-1],s[i]-b1,b3-s[i]}),dn=max(b0-s[i],s[i]-b2);
while(j>0&&s[j-1]>=b0-s[i]) --j;
while(k<n&&s[k]<s[i]-b2) ++k;
if(max(j,k)!=n&&s[max(j,k)]<=up) flag=1;
}
if(flag) R=mid;
else L=mid+1;
}
return L;
}
Compilation message
shortcut.cpp: In function 'void modify(ll, ll)':
shortcut.cpp:44:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(;x<=vec.size();x+=x&-x) bit[x]=max(bit[x],v);
~^~~~~~~~~~~~
shortcut.cpp: In function 'll find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:67:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<=vec.size();++i)
~^~~~~~~~~~~~
shortcut.cpp:73:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll mid=L+R>>1,mit=INF,b0=-INF,b1=-INF,b2=-1,b3=INF,flag=0;
~^~
shortcut.cpp:83:40: warning: unused variable 'dn' [-Wunused-variable]
ll up=min({s[n-1],s[i]-b1,b3-s[i]}),dn=max(b0-s[i],s[i]-b2);
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
304 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
256 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
384 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
256 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000623 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
304 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
256 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
384 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
256 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000623 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
304 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
256 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
384 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
256 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000623 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
304 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
256 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
384 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
256 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000623 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
304 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
256 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
384 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
256 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000623 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
304 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
256 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
384 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
256 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000623 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
304 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
256 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
384 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
256 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000623 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
304 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
256 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
384 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
256 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000623 |
18 |
Halted |
0 ms |
0 KB |
- |