# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
683047 | omikron123 | Balloons (CEOI11_bal) | C++14 | 236 ms | 10156 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// https://oj.uz/problem/view/CEOI11_bal
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <stack>
using namespace std;
typedef long long ll;
/*
1. y[i] = min( (x[i]-x[j])^2 / (4*y[j]) )
2. 检查每一个之前的气球导致O(n^2),会TLE.
3. 我们注意到:
a. 对于一个气球(y[i],x[i]),任何比这个气球位置更左,大小更小的气球都是不会和将来的气球接触到的。
b. 如果i碰到一个左侧更大的气球j,则肯定不会碰到j左侧更大的气球。
4. 所以问题变成了nearest larger value的问题,我们要维护一个直径单调减的气球的stack。
5. 每次新增气球时,从stack顶开始计算y[i],如果比栈顶大,就pop再计算。如果小于等于栈顶,则这个大小合适。
*/
int n; // 2e5
int x[200005], r[200005];
double ans[200005];
stack<pair<double,int>> st; // (radius, x), radius decreasing, x increasing
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d %d", &x[i], &r[i]);
for (int i = 0; i < n; i++) {
double y = r[i];
while (!st.empty()) {
y = min(y, (x[i]-st.top().second)*(x[i]-st.top().second) / st.top().first / 4);
if (y > st.top().first)
st.pop();
else
break;
}
st.push({y, x[i]});
ans[i] = y;
}
for (int i = 0; i < n; i++)
printf("%lf\n", ans[i]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |