Submission #577526

# Submission time Handle Problem Language Result Execution time Memory
577526 2022-06-15T03:50:47 Z tengiz05 Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
34 ms 5080 KB
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

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

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

i64 C(i64 x) {
    x = norm(x);
    return x * (x + 1) % P * D % P;
}

int main() {
    // freopen("input1.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    vector<i64> h(n + 1), w(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> w[i];
        w[i] += w[i - 1];
        w[i] %= P;
    }
    
    vector<i64> s{0};
    i64 sum = 0;
    
    i64 ans = 0;
    
    for (int i = 1; i <= n; i++) {
        while (h[s.back()] > h[i]) {
            i64 height = h[s.back()];
            i64 r = w[s.back()];
            s.pop_back();
            i64 l = w[s.back()];
            // cout << " what the hell " << l << " " << r << " : " << height << "\n";
            sum = norm(sum - (r - l) * C(height) % P);
            sum = norm(sum + (r - l) * C(h[i]) % P);
        }
        // cout << sum << "\n";
        ans = norm(ans + sum * (w[i] - w[i - 1]) % P);
        // cout << ans << " ";
        ans = norm(ans + C(w[i] - w[i - 1]) * C(h[i]) % P);
        // cout << ans << "\n";
        sum = norm(sum + (w[i] - w[i - 1]) * C(h[i]) % P);
        s.push_back(i);
    }
    
    cout << ans << "\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 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 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 9 ms 1492 KB Output is correct
4 Correct 22 ms 4180 KB Output is correct
5 Correct 20 ms 3664 KB Output is correct
6 Correct 20 ms 3184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 11 ms 1752 KB Output is correct
4 Correct 22 ms 3028 KB Output is correct
5 Correct 27 ms 3048 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 13 ms 1752 KB Output is correct
5 Correct 22 ms 3028 KB Output is correct
6 Correct 34 ms 2932 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 13 ms 1760 KB Output is correct
10 Correct 22 ms 3056 KB Output is correct
11 Correct 21 ms 3060 KB Output is correct
12 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 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 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 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 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 10 ms 1404 KB Output is correct
12 Correct 19 ms 4228 KB Output is correct
13 Correct 19 ms 3672 KB Output is correct
14 Correct 25 ms 3240 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 13 ms 2776 KB Output is correct
18 Correct 23 ms 4936 KB Output is correct
19 Correct 30 ms 5080 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 852 KB Output is correct
22 Correct 12 ms 2652 KB Output is correct
23 Correct 23 ms 4824 KB Output is correct
24 Correct 29 ms 4948 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 340 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 724 KB Output is correct
32 Correct 11 ms 2004 KB Output is correct
33 Correct 13 ms 2004 KB Output is correct
34 Correct 24 ms 3532 KB Output is correct
35 Correct 27 ms 3544 KB Output is correct
36 Correct 28 ms 3800 KB Output is correct
37 Correct 28 ms 3788 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 24 ms 3800 KB Output is correct
40 Correct 24 ms 3788 KB Output is correct
41 Correct 26 ms 4044 KB Output is correct
42 Correct 33 ms 4432 KB Output is correct