Submission #398187

# Submission time Handle Problem Language Result Execution time Memory
398187 2021-05-03T21:32:25 Z illyakr Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
107 ms 20848 KB
#include <iostream>
#define int long long

using namespace std;
const int mod = 1000000007;

int n;
int h[101010], w[101010];
int RMQ[30][101010];
int L[101010];
int pref[101010];

int get(int l, int r) {
    int x = L[r - l + 1];
    int f = RMQ[x][l], s = RMQ[x][r - (1 << x) + 1];
    if (h[f] <= h[s]) return f;
    return s;
}
int res = 0;

void rec(int l, int r, int nowH) {
    if (l > r)return;
    int go = get(l, r);
    int H = h[go] - nowH;
    int W = pref[r] - pref[l - 1];
    H %= mod; W %= mod;
    res += (((((W * (W + 1)) / 2) % mod) *
             (((H * (H + 1)) / 2) % mod)) % mod);
    res %= mod;
    res += (((((((W * (W + 1)) / 2) % mod) * H) % mod) * nowH) % mod);
    res %= mod;

//    cout << l << " " << r << " << " << endl;

    rec(l, go - 1, h[go]); rec(go + 1, r, h[go]);
    return;
}

int32_t main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> h[i];
    for (int i = 1; i <= n; i++)cin >> w[i];

    for (int i = 1; i <= n; i++) {
        pref[i] = pref[i - 1] + w[i];
    }

    L[1] = 0;
    for (int i = 2; i <= n; i++) L[i] = L[i / 2] + 1;
    for (int i = 1; i <= n; i++) RMQ[0][i] = i;
    for (int i = 1; i <= L[n]; i++) {
        for (int j = 1; j + (1 << i) - 1 <= n; j++) {
            if (h[RMQ[i - 1][j]] <= h[RMQ[i - 1][j + (1 << (i - 1))]])
                RMQ[i][j] = RMQ[i - 1][j];
            else
                RMQ[i][j] = RMQ[i - 1][j + (1 << (i - 1))];
        }
    }
    rec(1, n, 0);
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 36 ms 8248 KB Output is correct
4 Correct 68 ms 16868 KB Output is correct
5 Correct 74 ms 16924 KB Output is correct
6 Correct 68 ms 16892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 10 ms 1612 KB Output is correct
3 Correct 47 ms 7612 KB Output is correct
4 Correct 104 ms 15664 KB Output is correct
5 Correct 105 ms 15748 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 12 ms 1612 KB Output is correct
4 Correct 46 ms 7696 KB Output is correct
5 Correct 93 ms 15724 KB Output is correct
6 Correct 94 ms 15680 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 10 ms 1780 KB Output is correct
9 Correct 48 ms 8656 KB Output is correct
10 Correct 90 ms 17568 KB Output is correct
11 Correct 92 ms 17604 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 444 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 3 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 34 ms 8244 KB Output is correct
12 Correct 72 ms 16900 KB Output is correct
13 Correct 80 ms 16972 KB Output is correct
14 Correct 70 ms 16904 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 10 ms 1868 KB Output is correct
17 Correct 53 ms 8660 KB Output is correct
18 Correct 92 ms 17692 KB Output is correct
19 Correct 98 ms 17828 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 12 ms 1880 KB Output is correct
22 Correct 47 ms 8644 KB Output is correct
23 Correct 93 ms 17608 KB Output is correct
24 Correct 107 ms 17604 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 444 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 10 ms 1868 KB Output is correct
31 Correct 10 ms 1868 KB Output is correct
32 Correct 52 ms 8652 KB Output is correct
33 Correct 58 ms 8648 KB Output is correct
34 Correct 88 ms 17488 KB Output is correct
35 Correct 88 ms 17668 KB Output is correct
36 Correct 93 ms 17688 KB Output is correct
37 Correct 94 ms 17680 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 100 ms 17664 KB Output is correct
40 Correct 98 ms 17728 KB Output is correct
41 Correct 95 ms 18616 KB Output is correct
42 Correct 95 ms 20848 KB Output is correct