# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
552567 | 2022-04-23T10:13:52 Z | mars4 | Lightning Conductor (POI11_pio) | C++17 | 419 ms | 20968 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=19; 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 1520 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 2276 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 2600 KB | Output is correct |
2 | Correct | 33 ms | 2616 KB | Output is correct |
3 | Correct | 46 ms | 2756 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 77 ms | 3772 KB | Output is correct |
2 | Correct | 55 ms | 3772 KB | Output is correct |
3 | Correct | 78 ms | 4296 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 118 ms | 8500 KB | Output is correct |
2 | Correct | 113 ms | 8368 KB | Output is correct |
3 | Correct | 216 ms | 9004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 184 ms | 14780 KB | Output is correct |
2 | Correct | 207 ms | 12620 KB | Output is correct |
3 | Correct | 301 ms | 14776 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 309 ms | 20876 KB | Output is correct |
2 | Correct | 250 ms | 17996 KB | Output is correct |
3 | Correct | 419 ms | 20964 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 341 ms | 18508 KB | Output is correct |
2 | Correct | 253 ms | 18024 KB | Output is correct |
3 | Correct | 395 ms | 20968 KB | Output is correct |