Submission #152004

# Submission time Handle Problem Language Result Execution time Memory
152004 2019-09-05T20:24:18 Z dolphingarlic Lightning Conductor (POI11_pio) C++14
100 / 100
133 ms 19864 KB
#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]) {
	for(int i=0, qh=0, qt=0; i<n; ++i) {
		if(!i||h[qu[qt-1]]<h[i]) {
			while(qt>qh&&h[i]>=h[qu[qt-1]]+sr[i-qu[qt-1]]||qt-qh>1&&ix(qu[qt-2], qu[qt-1])>ix(qu[qt-1], i))
				--qt;
			qu[qt++]=i;
		}
		while(qt-qh>1&&i>ix(qu[qh], qu[qh+1]))
			++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";
}

Compilation message

pio.cpp: In function 'void solve(int*)':
pio.cpp:15:15: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    while(qt>qh&&h[i]>=h[qu[qt-1]]+sr[i-qu[qt-1]]||qt-qh>1&&ix(qu[qt-2], qu[qt-1])>ix(qu[qt-1], i))
          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 5880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 6056 KB Output is correct
2 Correct 16 ms 5372 KB Output is correct
3 Correct 19 ms 5880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 6876 KB Output is correct
2 Correct 29 ms 6776 KB Output is correct
3 Correct 27 ms 6904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 10232 KB Output is correct
2 Correct 56 ms 9848 KB Output is correct
3 Correct 54 ms 9848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 15384 KB Output is correct
2 Correct 86 ms 13176 KB Output is correct
3 Correct 83 ms 13944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 19864 KB Output is correct
2 Correct 120 ms 17020 KB Output is correct
3 Correct 119 ms 18040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 17620 KB Output is correct
2 Correct 122 ms 17144 KB Output is correct
3 Correct 116 ms 18076 KB Output is correct