Submission #979483

#TimeUsernameProblemLanguageResultExecution timeMemory
979483michifiedLightning Conductor (POI11_pio)C++17
45 / 100
629 ms13968 KiB
#include <bits/stdc++.h>
using namespace std;

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

    int n, i, cur = 0, at = 0, tmp, j;
    cin >> n;
    vector<int> h(n), ans(n);
    for (i = 0; i < n; i++) cin >> h[i];

    vector<int> hull = {0};
    for (i = 1; i < n; i++) {
        if (h[i] > h[hull.back()]) hull.push_back(i);
    }
    for (i = 0; i < n; i++) {
        if (at < hull.size() - 1 and i == hull[at + 1]) at++;
        j = at;
        tmp = cur;
        while (j > cur and h[hull[j]] + sqrt(i - hull[j]) >= h[hull[cur]] + sqrt(i - hull[cur])) {
            tmp = j;
            j--;
        }
        cur = tmp;
        while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[cur + 1]] + sqrt(i - hull[cur + 1])) cur++;
        ans[i] = max(ans[i], (int) ceil(h[hull[cur]] + sqrt(i - hull[cur])));
    }

    reverse(h.begin(), h.end());
    reverse(ans.begin(), ans.end());
    hull = {0};
    for (i = 1; i < n; i++) {
        if (h[i] > h[hull.back()]) hull.push_back(i);
    }
    cur = 0, at = 0;
    for (i = 0; i < n; i++) {
        if (at < hull.size() - 1 and i == hull[at + 1]) at++;
        j = at;
        tmp = cur;
        while (j > cur and h[hull[j]] + sqrt(i - hull[j]) >= h[hull[cur]] + sqrt(i - hull[cur])) {
            tmp = j;
            j--;
        }
        cur = tmp;
        while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[cur + 1]] + sqrt(i - hull[cur + 1])) cur++;
        ans[i] = max(ans[i], (int) ceil(h[hull[cur]] + sqrt(i - hull[cur])));
    }

    reverse(ans.begin(), ans.end());
    reverse(h.begin(), h.end());
    for (i = 0; i < n; i++) cout << max(0, ans[i] - h[i]) << endl;
    return 0;
}

Compilation message (stderr)

pio.cpp: In function 'int main()':
pio.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         if (at < hull.size() - 1 and i == hull[at + 1]) at++;
      |             ~~~^~~~~~~~~~~~~~~~~
pio.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[cur + 1]] + sqrt(i - hull[cur + 1])) cur++;
      |                ~~~~^~~~~~~~~~~~~~~~~
pio.cpp:38:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         if (at < hull.size() - 1 and i == hull[at + 1]) at++;
      |             ~~~^~~~~~~~~~~~~~~~~
pio.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[cur + 1]] + sqrt(i - hull[cur + 1])) cur++;
      |                ~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...