#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[2][1000005];
vector<ll> vec;
void modify(ll x,ll v,ll t)
{
if(t==0)
for(;x<=vec.size();x+=x&-x) bit[0][x]=max(bit[0][x],v);
else
for(;x<=vec.size();x+=x&-x) bit[1][x]=min(bit[1][x],v);
}
ll query(ll x,ll t)
{
ll re;
if(t==0)
for(re=-INF;x;x-=x&-x) re=max(re,bit[0][x]);
else
for(re=INF;x;x-=x&-x) re=min(re,bit[1][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=0;i<n;++i)
idx[i]=upper_bound(ALL(vec),s[i]-d[i])-vec.begin();
while(L<R)
{
ll mid=L+R>>1,b0=-INF,b1=-INF,b2=-1,b3=INF,flag=0;
for(int i=1;i<=vec.size();++i)
bit[0][i]=-INF,bit[1][i]=INF;
for(int i=1;i<n;++i)
{
modify(idx[i-1],s[i-1]+d[i-1],0),modify(idx[i-1],s[i-1]-d[i-1],1);
ll p=lower_bound(ALL(vec),s[i]+d[i]-mid)-vec.begin(),mx=query(p,0),mi=query(p,1);
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=-1;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+1<n&&s[k+1]>=s[i]-b2) ++k;
if(max(j,k)!=s.size()&&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, ll)':
shortcut.cpp:45:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(;x<=vec.size();x+=x&-x) bit[0][x]=max(bit[0][x],v);
~^~~~~~~~~~~~
shortcut.cpp:47:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(;x<=vec.size();x+=x&-x) bit[1][x]=min(bit[1][x],v);
~^~~~~~~~~~~~
shortcut.cpp: In function 'll find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:77:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll mid=L+R>>1,b0=-INF,b1=-INF,b2=-1,b3=INF,flag=0;
~^~
shortcut.cpp:78:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<=vec.size();++i)
~^~~~~~~~~~~~
shortcut.cpp:92:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(max(j,k)!=s.size()&&s[max(j,k)]<=up) flag=1;
~~~~~~~~^~~~~~~~~~
shortcut.cpp:89: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);
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
256 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 |
384 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 |
256 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 |
256 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 |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 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 |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
384 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
384 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
256 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 |
384 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 |
256 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 |
256 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 |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 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 |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
384 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
384 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
256 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 |
384 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 |
256 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 |
256 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 |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 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 |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
384 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
384 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
256 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 |
384 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 |
256 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 |
256 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 |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 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 |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
384 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
384 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
256 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 |
384 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 |
256 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 |
256 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 |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 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 |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
384 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
384 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
256 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 |
384 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 |
256 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 |
256 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 |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 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 |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
384 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
384 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
256 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 |
384 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 |
256 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 |
256 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 |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 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 |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
384 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
384 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
256 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 |
384 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 |
256 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 |
256 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 |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 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 |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
384 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
2 ms |
384 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318 |
18 |
Halted |
0 ms |
0 KB |
- |