# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
552566 | 2022-04-23T10:11:28 Z | mars4 | Lightning Conductor (POI11_pio) | C++17 | 443 ms | 21608 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ff first #define ss second #define ll int64_t #define ld long double #define nl cout<<"\n" #define i128 __int128_t #define all(v) v.begin(),v.end() #define mset(a,v) memset((a),(v),sizeof(a)) #define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i) #define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i) #define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define mod 1'000'000'007 #define mod2 998'244'353 #define inf 1'000'000'000'000'007 #define pi 3.14159265358979323846 template<class key,class cmp=std::less<key>> using ordered_set=tree<key,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>; template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p) {return out<<"("<<p.ff<<", "<<p.ss<<")";} template<class T> ostream& operator<<(ostream& out,vector<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,deque<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class T> ostream& operator<<(ostream& out,ordered_set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m) {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";} void dbg_out() {cerr<<"]\n";} template<typename Head,typename... Tail> void dbg_out(Head H,Tail... T) {cerr<<H;if(sizeof...(Tail))cerr<<", ";dbg_out(T...);} #ifdef LOCAL #define dbg(...) cerr<<"["<<#__VA_ARGS__<<"] = [",dbg_out(__VA_ARGS__) #else #define dbg(...) #endif //---------------------------------mars4--------------------------------- int main() { fastio(); ll z,n,m,t,k,i,j,l,d,h,r; cin>>n; vector<ll> a(n); for(ll &i:a) { cin>>i; } vector<ld> sq(n); forn(i,0,n) { sq[i]=sqrtl(i); } vector<ll> ans(n); // pl=hl-h+sqrt(i-l) // pr=hr-h+sqrt(i-r) // we want pl>=pr // hl-h+sqrt(i-l)>=hr-h+sqrt(i-r) // sqrt(i-l)-sqrt(i-r)>=hr-hl // we want greatest i such that the above condition is satisfied auto intersectX=[&](pair<ll,ll> a,pair<ll,ll> b) { ll logN=20; auto [hl,l]=a; auto [hr,r]=b; ll ind=r; forb(k,logN-1,0) { ll nind=ind+(1ll<<k); if(nind<n and sq[nind-l]-sq[nind-r]>=hr-hl) { ind=nind; } } return ind; }; auto val=[&](ll hi,ll hj,ll i,ll j) { return hj-hi+(ll)ceill(sq[i-j]); }; forn(k,0,2) { deque<pair<ll,ll>> dq; forn(i,0,n) { m=(ll)dq.size(); if(dq.empty() or a[i]>dq[m-1].ff) { while(m>=2 and intersectX(dq[m-1],{a[i],i})<=intersectX(dq[m-2],dq[m-1])) { dq.pop_back(); m--; } dq.push_back({a[i],i}); m++; } while(m>=2 and intersectX(dq[0],dq[1])<i) { dq.pop_front(); m--; } ans[i]=max(ans[i],val(a[i],dq[0].ff,i,dq[0].ss)); } reverse(all(a)); reverse(all(ans)); } for(ll i:ans) { cout<<i<<"\n"; } cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 1820 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 2764 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 50 ms | 3232 KB | Output is correct |
2 | Correct | 41 ms | 2744 KB | Output is correct |
3 | Correct | 58 ms | 3240 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 75 ms | 4388 KB | Output is correct |
2 | Correct | 65 ms | 4428 KB | Output is correct |
3 | Correct | 94 ms | 4852 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 143 ms | 9220 KB | Output is correct |
2 | Correct | 147 ms | 9000 KB | Output is correct |
3 | Correct | 240 ms | 9716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 225 ms | 15416 KB | Output is correct |
2 | Correct | 216 ms | 13376 KB | Output is correct |
3 | Correct | 336 ms | 15416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 316 ms | 21480 KB | Output is correct |
2 | Correct | 303 ms | 18572 KB | Output is correct |
3 | Correct | 443 ms | 21592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 407 ms | 19148 KB | Output is correct |
2 | Correct | 306 ms | 18524 KB | Output is correct |
3 | Correct | 435 ms | 21608 KB | Output is correct |