Submission #167464

# Submission time Handle Problem Language Result Execution time Memory
167464 2019-12-08T15:49:17 Z Thuleanx Lightning Conductor (POI11_pio) C++14
72 / 100
1000 ms 23212 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 5e5+7;
int n;
int h[N];
int L[N], R[N];
int sqr[N];

struct Sol {
	int i, high;
	Sol(int i, int high):i(i), high(high) {}
	int value(int j) { return high + ceil(sqrt(j-i)); }
	long double actual_value(int j) { return high + sqrt(j-i); }
	int to(Sol &other) {
		int lo = other.i, hi = n-1;
		while (lo <= hi) {
			int mid = lo+hi>>1;	
			if (actual_value(mid) >= other.actual_value(mid)) 	lo = mid+1;
			else												hi = mid-1;
		}
		return lo;
	}
};

void solve(int A[]) {
	deque<Sol> dq;
	for (int i = 0; i < n; i++) {
		while (dq.size() >= 2 && dq[0].value(i) < dq[1].value(i))
			dq.pop_front();
		if (dq.size())
			A[i] = dq.front().value(i);

		Sol sol(i, h[i]);
		while (dq.size() && dq.back().to(sol) <= i)
			dq.pop_back();
		while (dq.size() >= 2 && dq[dq.size()-2].to(dq.back()) > dq.back().to(sol))
			dq.pop_back();
		if (dq.size() && dq.back().to(sol) == n) continue;
		dq.push_back(sol);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	memset(sqr,0,sizeof(sqr));
	for (int i = 0; i*i+1 < N; i++) 
		sqr[i*i+1] = i+1;
	for (int i = 1; i < N; i++)
		sqr[i] = max(sqr[i], sqr[i-1]);
	for (int i = 0; i < n; i++)
		cin>>h[i];

	solve(L);
	reverse(h, h+n);
	solve(R);
	reverse(h, h+n);
	reverse(R, R+n);

	stringstream ss;
	for (int i = 0; i < n; i++) 
		ss << max(0, max(L[i],R[i])-h[i]) << endl;
	cout << ss.str();

	return 0;
}

Compilation message

pio.cpp: In member function 'int Sol::to(Sol&)':
pio.cpp:18:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    int mid = lo+hi>>1; 
              ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 3748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 4488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 4172 KB Output is correct
2 Correct 83 ms 4216 KB Output is correct
3 Correct 132 ms 5104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 4980 KB Output is correct
2 Correct 137 ms 5760 KB Output is correct
3 Incorrect 212 ms 7076 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 334 ms 8420 KB Output is correct
2 Correct 327 ms 9940 KB Output is correct
3 Correct 517 ms 11284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 532 ms 16896 KB Output is correct
2 Correct 646 ms 10776 KB Output is correct
3 Correct 852 ms 17148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 774 ms 23212 KB Output is correct
2 Correct 761 ms 14364 KB Output is correct
3 Execution timed out 1076 ms 8092 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 910 ms 15896 KB Output is correct
2 Correct 767 ms 19352 KB Output is correct
3 Execution timed out 1084 ms 12180 KB Time limit exceeded