#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}
const int N=5e5+5;
int intersect(pair<int,int> a,pair<int,int> b){ //h,i
assert(a.f<b.f&&a.s<b.s);
int dist=b.s-a.s;
int diff=b.f-a.f;
int l=0,r=5*N;
while(l<r){
int m=(l+r)>>1;
if(sqrt(m+dist)-sqrt(m)<=diff){
r=m;
}
else{
l=m+1;
}
}
return min(N,l+b.s);
}
int findP(int hj,int hi,int inddiff){
return ceil(hj-hi+sqrtl(inddiff));
}
int main()
{
int n=ri();
vector<int> h(n);
rd(h);
vector<int> l(n),r(n);
for(int k=0;k<2;k++){
deque<pair<int,int>> cand;
cand.pb({h[0],0});
vector<int> inc;
inc.pb(0);
for(int i=1;i<n;i++){
while(cand.size()>1&&intersect(cand[0],cand[1])<=i)
cand.pop_front();
l[i]=findP(cand[0].f,h[i],i-cand[0].s);
for(int j=0;j<inc.size();j++)
l[i]=max(l[i],findP(h[inc[j]],h[i],i-inc[j]));
if(h[i]>cand.back().f){
assert(h[i]>h[inc.back()]);
while(cand.size()>1&&intersect(cand[cand.size()-1],{h[i],i})<=intersect(cand[cand.size()-2],cand[cand.size()-1])){
cand.pop_back();
}
cand.push_back({h[i],i});
}
if(h[i]>h[inc.back()])
inc.pb(i);
}
reverse(all(h));
swap(l,r);
}
reverse(all(r));
for(int i=0;i<n;i++)
printf("%i\n",max(l[i],r[i]));
return 0;
}
Compilation message
pio.cpp: In function 'int main()':
pio.cpp:82:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int j=0;j<inc.size();j++)
| ~^~~~~~~~~~~
pio.cpp: In function 'int ri()':
pio.cpp:33:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | int ri(){int x;scanf("%i",&x);return x;}
| ~~~~~^~~~~~~~~
pio.cpp: In function 'void rd(int&)':
pio.cpp:34:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | void rd(int&x){scanf("%i",&x);}
| ~~~~~^~~~~~~~~
pio.cpp: In function 'void rd(long long int&)':
pio.cpp:35:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | void rd(long long&x){scanf("%lld",&x);}
| ~~~~~^~~~~~~~~~~
pio.cpp: In function 'void rd(double&)':
pio.cpp:36:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | void rd(double&x){scanf("%lf",&x);}
| ~~~~~^~~~~~~~~~
pio.cpp: In function 'void rd(long double&)':
pio.cpp:37:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | void rd(long double&x){scanf("%Lf",&x);}
| ~~~~~^~~~~~~~~~
pio.cpp: In function 'void rd(char*)':
pio.cpp:39:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | void rd(char*x){scanf("%s",x);}
| ~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
852 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
1276 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
1308 KB |
Output is correct |
2 |
Correct |
18 ms |
1224 KB |
Output is correct |
3 |
Correct |
220 ms |
1568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
1836 KB |
Output is correct |
2 |
Correct |
36 ms |
1844 KB |
Output is correct |
3 |
Correct |
319 ms |
2336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
3996 KB |
Output is correct |
2 |
Correct |
76 ms |
3880 KB |
Output is correct |
3 |
Correct |
761 ms |
4524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
177 ms |
7876 KB |
Output is correct |
2 |
Correct |
129 ms |
5756 KB |
Output is correct |
3 |
Execution timed out |
1092 ms |
4420 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
202 ms |
11076 KB |
Output is correct |
2 |
Correct |
156 ms |
8132 KB |
Output is correct |
3 |
Execution timed out |
1070 ms |
6172 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
300 ms |
8596 KB |
Output is correct |
2 |
Correct |
153 ms |
8132 KB |
Output is correct |
3 |
Execution timed out |
1093 ms |
6100 KB |
Time limit exceeded |