# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
552561 | 2022-04-23T09:58:59 Z | mars4 | Lightning Conductor (POI11_pio) | C++17 | 237 ms | 25692 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)ceil(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(); } 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 | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | Runtime error | 5 ms | 2644 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 9 ms | 4044 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 3244 KB | Output is correct |
2 | Correct | 16 ms | 2724 KB | Output is correct |
3 | Correct | 35 ms | 3228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 4732 KB | Output is correct |
2 | Correct | 21 ms | 4732 KB | Output is correct |
3 | Correct | 44 ms | 4944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 10760 KB | Output is correct |
2 | Correct | 49 ms | 10316 KB | Output is correct |
3 | Correct | 120 ms | 10404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 76 ms | 18164 KB | Output is correct |
2 | Correct | 78 ms | 16116 KB | Output is correct |
3 | Correct | 200 ms | 16844 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 113 ms | 25692 KB | Output is correct |
2 | Correct | 111 ms | 22784 KB | Output is correct |
3 | Correct | 237 ms | 23864 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 204 ms | 23376 KB | Output is correct |
2 | Correct | 104 ms | 22852 KB | Output is correct |
3 | Correct | 236 ms | 23796 KB | Output is correct |