Submission #29550

# Submission time Handle Problem Language Result Execution time Memory
29550 2017-07-20T06:02:04 Z 김동현(#1239) Lightning Conductor (POI11_pio) C++14
27 / 100
196 ms 13740 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int n;
ll h[500010], la[500010], ra[500010];

struct CHT{
	struct Cnv{ ll a, b; };
	ll inv(Cnv p, ll y){
		ll s = 0, e = 710;
		while(s <= e){
			ll m = (s + e) / 2;
			if(m * m >= y - p.b) e = m - 1;
			else s = m + 1;
		}
		return s + p.a;
	}
	deque<Cnv> dq;
	int r;
	void ini(){ dq.clear(); r = 0; }
	void upd(ll a, ll b){
		Cnv cur = {a, b};
		if(!dq.empty() && dq.back().a >= cur.a) return;
		while(dq.size() > 1 && inv(dq[r - 1], cur.b) <= inv(dq[r - 2], cur.b)){ dq.pop_back(); r--; }
		dq.push_back(cur); r++;
	}
	ll get(ll y){
		if(dq.empty()) return 0;
		while(dq.size() > 1 && inv(dq[0], y) <= inv(dq[1], y)) dq.pop_front();
		return inv(dq[0], y);
	}
} C;

void f(ll *a){
	C.ini();
	for(int i = 1; i <= n; i++){
		a[i] = max(h[i], C.get(i));
		C.upd(h[i], i);
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%lld", h + i);
	f(la);
	reverse(h + 1, h + n + 1);
	f(ra);
	reverse(h + 1, h + n + 1);
	for(int i = 1; i <= n; i++) printf("%lld\n", max(la[i], ra[n + 1 - i]) - h[i]);
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:45:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
pio.cpp:46:50: 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("%lld", h + i);
                                                  ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 13740 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 13740 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 13740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 13740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 13740 KB Output is correct
2 Correct 13 ms 13740 KB Output is correct
3 Incorrect 19 ms 13740 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 13740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 13740 KB Output is correct
2 Correct 56 ms 13740 KB Output is correct
3 Incorrect 63 ms 13740 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 13740 KB Output is correct
2 Correct 116 ms 13740 KB Output is correct
3 Incorrect 139 ms 13740 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 196 ms 13740 KB Output is correct
2 Correct 153 ms 13740 KB Output is correct
3 Incorrect 186 ms 13740 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 183 ms 13740 KB Output isn't correct
2 Halted 0 ms 0 KB -