Submission #81845

#TimeUsernameProblemLanguageResultExecution timeMemory
81845tmwilliamlin168Lightning Conductor (POI11_pio)C++14
91 / 100
157 ms23128 KiB
#include <bits/stdc++.h> using namespace std; const int mxN=5e5; int n, h[mxN], a1[mxN], a2[mxN], sr[1000001], qu[mxN]; double ix(int i, int j) { double a=(j-i)/2.0/(h[j]-h[i])-(h[j]-h[i])/2.0; return a*a+j; } void solve(int a[mxN]) { int qh=0, qt=0; for(int i=0; i<n; ++i) { if(!i||h[qu[qt-1]]<h[i]) { while(qt-qh>1&&(h[i]>=h[qu[qt-1]]+sr[i-qu[qt-1]]||ix(qu[qt-2], qu[qt-1])>ix(qu[qt-1], i))) --qt; qu[qt++]=i; } while(qt-qh>1&&h[qu[qh+1]]+sr[i-qu[qh+1]]>h[qu[qh]]+sr[i-qu[qh]]) ++qh; a[i]=h[qu[qh]]+sr[i-qu[qh]]; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); for(int i=1; i<=1000; ++i) for(int j=(i-1)*(i-1)+1; j<=i*i; ++j) sr[j]=i; cin >> n; for(int i=0; i<n; ++i) cin >> h[i]; solve(a1); for(int i=0; i<n-1-i; ++i) swap(h[i], h[n-1-i]); solve(a2); for(int i=0; i<n; ++i) cout << max(a1[i], a2[n-1-i])-h[n-1-i] << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...