Submission #544167

# Submission time Handle Problem Language Result Execution time Memory
544167 2022-04-01T09:19:55 Z tengiz05 Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>

using i64 = long long;

constexpr int P = 1E9 + 7;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n;
    std::cin >> n;
    
    std::vector<i64> h(n + 1), w(n + 1);
    for (int i = 1; i <= n; i++) {
        std::cin >> h[i];
    }
    for (int i = 1; i <= n; i++) {
        std::cin >> w[i];
        w[i] += w[i - 1];
    }
    
    std::vector<std::pair<i64, i64>> s;
    s.emplace_back(0, 0);
    
    i64 a = 0;
    i64 ans = 0;
    
    for (int i = 1; i <= n; i++) {
        while (s.back().first >= h[i]) {
            i64 x = s.back().second - s[int(s.size()) - 2].second;
            a -= s.back().first * (x * (x + 1) / 2);
            s.pop_back();
        }
        if (s.back().second != w[i - 1]) {
            i64 x = w[i - 1] - s.back().second;
            a += h[i] * (x * (x + 1) / 2);
            s.emplace_back(h[i], w[i - 1]);
        }
        ans += a % P * (w[i] - w[i - 1]) % P;
        i64 x = w[i] - w[i - 1];
        i64 y = h[i];
        ans += (x * (x + 1) / 2 % P) * (y * (y + 1) / 2 % P) % P;
        a += h[i] * (w[i] - s.back().second);
        s.emplace_back(h[i], w[i]);
    }
    
    std::cout << ans << "\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -