Submission #544178

# Submission time Handle Problem Language Result Execution time Memory
544178 2022-04-01T09:38:11 Z tengiz05 Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
39 ms 5976 KB
#include <bits/stdc++.h>

using i64 = long long;

constexpr int P = 1E9 + 7, two = (P + 1) / 2;

i64 norm(i64 x) {
    if (x >= P) {
        x -= P;
    } else if (x < 0) {
        x += P;
    }
    return x;
}

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) % P;
            a = norm(a - x * (s.back().first * (s.back().first + 1) / 2 % P) % P);
            s.pop_back();
        }
        if (s.back().second != w[i - 1]) {
            i64 x = (w[i - 1] - s.back().second) % P;
            a = norm(a + x * (h[i] * (h[i] + 1) / 2 % P) % P);
            s.emplace_back(h[i], w[i - 1]);
        }
        i64 x = (w[i] - w[i - 1]) % P;
        i64 y = h[i];
        ans = norm(ans + a % P * x % P);
        ans = norm(ans + (x * (x + 1) % P * two % P) * (y * (y + 1) % P * two % P) % P);
        a = norm(a + (h[i] * (h[i] + 1) / 2 % P) * x % P);
        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 Correct 1 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 13 ms 1616 KB Output is correct
4 Correct 21 ms 3052 KB Output is correct
5 Correct 23 ms 3048 KB Output is correct
6 Correct 25 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 5 ms 616 KB Output is correct
3 Correct 15 ms 2008 KB Output is correct
4 Correct 28 ms 3808 KB Output is correct
5 Correct 31 ms 3920 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 4 ms 584 KB Output is correct
4 Correct 14 ms 1992 KB Output is correct
5 Correct 28 ms 3792 KB Output is correct
6 Correct 30 ms 3920 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 3 ms 980 KB Output is correct
9 Correct 15 ms 2768 KB Output is correct
10 Correct 26 ms 5840 KB Output is correct
11 Correct 26 ms 5976 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 360 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 11 ms 1684 KB Output is correct
12 Correct 34 ms 3036 KB Output is correct
13 Correct 21 ms 3020 KB Output is correct
14 Correct 24 ms 3020 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 13 ms 2004 KB Output is correct
18 Correct 39 ms 3724 KB Output is correct
19 Correct 33 ms 3924 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 3 ms 980 KB Output is correct
22 Correct 15 ms 2768 KB Output is correct
23 Correct 27 ms 5856 KB Output is correct
24 Correct 26 ms 5976 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 352 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 4 ms 596 KB Output is correct
32 Correct 14 ms 1876 KB Output is correct
33 Correct 14 ms 2004 KB Output is correct
34 Correct 36 ms 3552 KB Output is correct
35 Correct 26 ms 3552 KB Output is correct
36 Correct 32 ms 3792 KB Output is correct
37 Correct 29 ms 3796 KB Output is correct
38 Correct 1 ms 320 KB Output is correct
39 Correct 36 ms 3796 KB Output is correct
40 Correct 28 ms 3804 KB Output is correct
41 Correct 27 ms 4296 KB Output is correct
42 Correct 30 ms 4960 KB Output is correct