Submission #141622

# Submission time Handle Problem Language Result Execution time Memory
141622 2019-08-08T14:41:14 Z abacaba Lightning Conductor (POI11_pio) C++14
100 / 100
322 ms 9284 KB
#include <bits/stdc++.h>
using namespace std;
 
struct point {
	int i, l, r;
};
 
const int N = 5e5 + 15;
int n, a[N], dp[N];
deque <point> q;
 
inline double get(int j, int i) {
	return a[i] + sqrt(abs(i - j));
}
 
void process() {
	q.clear();
	for(int i = 1; i <= n; ++i) {
		while(!q.empty() && q.front().r < i)
			q.pop_front();
		while(!q.empty() && get(max(i, q.back().l), q.back().i) <= get(max(i, q.back().l), i))
			q.pop_back();
		if(q.empty())
			q.push_back({i, i, n});
		else {
			int l = max(i, q.back().l), r = q.back().r, res = 0;
			while(l <= r) {
				int mid = l + r >> 1;
				if(get(mid, i) >= get(mid, q.back().i))
					res = mid, r = mid - 1;
				else
					l = mid + 1;
			}
			if(res) {
				if(res - 1 >= q.back().l)
					q.back().r = res - 1;
				else
					q.pop_back();
				q.push_back({i, res, n});
			}
		}
		dp[i] = max(dp[i], (int)ceil(get(i, q.front().i)) - a[i]);
	}
}
 
 
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	process();
	reverse(a + 1, a + 1 + n);
	reverse(dp + 1, dp + 1 + n);
	process();
	for(int i = n; i; --i)
		printf("%d\n", dp[i]);
    return 0;
}

Compilation message

pio.cpp: In function 'void process()':
pio.cpp:28:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
pio.cpp: In function 'int main()':
pio.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
pio.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 1068 KB Output is correct
2 Correct 32 ms 1140 KB Output is correct
3 Correct 38 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 1556 KB Output is correct
2 Correct 55 ms 1624 KB Output is correct
3 Correct 56 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 3196 KB Output is correct
2 Correct 130 ms 2996 KB Output is correct
3 Correct 128 ms 3728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 224 ms 6520 KB Output is correct
2 Correct 201 ms 4472 KB Output is correct
3 Correct 207 ms 6716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 322 ms 9256 KB Output is correct
2 Correct 289 ms 6392 KB Output is correct
3 Correct 297 ms 9208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 306 ms 6844 KB Output is correct
2 Correct 289 ms 6240 KB Output is correct
3 Correct 300 ms 9284 KB Output is correct