Submission #241638

# Submission time Handle Problem Language Result Execution time Memory
241638 2020-06-24T22:06:37 Z ChrisT Lightning Conductor (POI11_pio) C++17
100 / 100
740 ms 17016 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pib = pair<int,bool>;
using ll = long long;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#ifdef fread_unlocked
#define fread fread_unlocked
#define fwrite fwrite_unlocked
#endif
#define lc ind<<1
#define rc ind<<1|1
const int MN = 501265, MOD = 1e9+7, BASE = 31;
int h[MN]; ld mx[MN];
ld get (int x, int y) {
	return h[y] + sqrtl(abs(x-y));
}
int intersect (int a, int b) { //when does a pass b?
	int low = 1, high = min(a,b) - 1, mid, ans = 0;
	while (low <= high) {
		mid = (low + high) / 2;
		if (get(mid,a) > get(mid,b)) low = (ans = mid) + 1;
		else high = mid - 1;
	}
	return ans;
}
// -1 -1 -1 -1 0 0 0 0 1 1 1 1
int main () {
	int n;
	scanf ("%d",&n);
	for (int i = 1; i <= n; i++) scanf ("%d",h+i);
	deque<int> dq;
	for (int i = n; i >= 1; i--) {
		while ((int)dq.size()>1 && get(i,dq.front()) < get(i,dq[1])) dq.pop_front();
		if (i<n) mx[i] = max(mx[i],get(i,dq.front()));
		while ((int)dq.size() > 1 && intersect(i,dq.back()) > intersect(dq.back(),dq[(int)dq.size()-2])) dq.pop_back();
		dq.push_back(i);
	}
	dq.clear();
	reverse(h+1,h+1+n);
	for (int i = n; i >= 1; i--) {
		while ((int)dq.size()>1 && get(i,dq.front()) < get(i,dq[1])) dq.pop_front();
		if (i<n) mx[n-i+1] = max(mx[n-i+1],get(i,dq.front()));
		while ((int)dq.size() > 1 && intersect(i,dq.back()) > intersect(dq.back(),dq[(int)dq.size()-2])) dq.pop_back();
		dq.push_back(i);
	}
	for (int i = 1; i <= n; i++) printf ("%d\n",(int)ceill(max((ld)0,mx[i] - h[n-i+1])));
	return 0;
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d",&n);
  ~~~~~~^~~~~~~~~
pio.cpp:32:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf ("%d",h+i);
                               ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 1968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 1912 KB Output is correct
2 Correct 53 ms 2152 KB Output is correct
3 Correct 87 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 2680 KB Output is correct
2 Correct 124 ms 2808 KB Output is correct
3 Correct 136 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 332 ms 5880 KB Output is correct
2 Correct 296 ms 7628 KB Output is correct
3 Correct 316 ms 7676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 530 ms 10704 KB Output is correct
2 Correct 464 ms 9036 KB Output is correct
3 Correct 508 ms 12368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 739 ms 15096 KB Output is correct
2 Correct 649 ms 12612 KB Output is correct
3 Correct 713 ms 17016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 740 ms 12596 KB Output is correct
2 Correct 679 ms 14532 KB Output is correct
3 Correct 714 ms 16760 KB Output is correct