Submission #534888

# Submission time Handle Problem Language Result Execution time Memory
534888 2022-03-09T05:48:25 Z mjhmjh1104 Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
52 ms 7148 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int MOD = 1e9 + 7;

int n, h[100006], w[100006], res, sum[100006];
vector<int> v;

int get(int x, int y) {
    return (sum[y] - (x ? sum[x - 1] : 0) + MOD) % MOD;
}

pair<int, int> tree[262144];

pair<int, int> query(int i, int b, int e, int l, int r) {
    if (r < l || r < b || e < l) return { (int)2e9, -1 };
    if (l <= b && e <= r) return tree[i];
    int m = (b + e) / 2;
    return min(query(i * 2 + 1, b, m, l, r), query(i * 2 + 2, m + 1, e, l, r));
}

void dnc(int l, int r, int curr) {
    if (l > r) return;
    int m = query(0, 0, 131071, l, r).second;
    int c = get(l, r);
    int x = (1LL * h[m] * (h[m] + 1) / 2 % MOD - 1LL * curr * (curr + 1) / 2 % MOD + MOD) % MOD;
    res = (res + 1LL * x * (1LL * c * (c + 1) / 2 % MOD) % MOD) % MOD;
    dnc(l, m - 1, h[m]);
    dnc(m + 1, r, h[m]);
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", h + i);
    for (int i = 0; i < n; i++) scanf("%d", w + i);
    sum[0] = w[0];
    for (int i = 1; i < n; i++) sum[i] = (sum[i - 1] + w[i]) % MOD;
    for (int i = 0; i < n; i++) tree[131071 + i] = { h[i], i };
    for (int i = 131070; i >= 0; i--) tree[i] = min(tree[i * 2 + 1], tree[i * 2 + 2]);
    dnc(0, n - 1, 0);
    printf("%d", res);
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
fancyfence.cpp:36:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     for (int i = 0; i < n; i++) scanf("%d", h + i);
      |                                 ~~~~~^~~~~~~~~~~~~
fancyfence.cpp:37:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     for (int i = 0; i < n; i++) scanf("%d", w + i);
      |                                 ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1212 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 22 ms 2252 KB Output is correct
4 Correct 46 ms 3140 KB Output is correct
5 Correct 43 ms 3192 KB Output is correct
6 Correct 41 ms 3228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1228 KB Output is correct
2 Correct 8 ms 1508 KB Output is correct
3 Correct 24 ms 2288 KB Output is correct
4 Correct 49 ms 3256 KB Output is correct
5 Correct 52 ms 3244 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 2 ms 1228 KB Output is correct
3 Correct 7 ms 1420 KB Output is correct
4 Correct 26 ms 2268 KB Output is correct
5 Correct 52 ms 3184 KB Output is correct
6 Correct 51 ms 3240 KB Output is correct
7 Correct 2 ms 1228 KB Output is correct
8 Correct 6 ms 1484 KB Output is correct
9 Correct 24 ms 2292 KB Output is correct
10 Correct 47 ms 3240 KB Output is correct
11 Correct 49 ms 3200 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 3 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 2 ms 1228 KB Output is correct
9 Correct 2 ms 1228 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 2 ms 1228 KB Output is correct
14 Correct 2 ms 1228 KB Output is correct
15 Correct 1 ms 1228 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 2 ms 1228 KB Output is correct
11 Correct 22 ms 2236 KB Output is correct
12 Correct 45 ms 3244 KB Output is correct
13 Correct 43 ms 3240 KB Output is correct
14 Correct 47 ms 3244 KB Output is correct
15 Correct 2 ms 1228 KB Output is correct
16 Correct 6 ms 1468 KB Output is correct
17 Correct 27 ms 2244 KB Output is correct
18 Correct 52 ms 3236 KB Output is correct
19 Correct 49 ms 3140 KB Output is correct
20 Correct 2 ms 1228 KB Output is correct
21 Correct 6 ms 1484 KB Output is correct
22 Correct 25 ms 2288 KB Output is correct
23 Correct 48 ms 3260 KB Output is correct
24 Correct 48 ms 3148 KB Output is correct
25 Correct 1 ms 1228 KB Output is correct
26 Correct 1 ms 1228 KB Output is correct
27 Correct 2 ms 1228 KB Output is correct
28 Correct 1 ms 1228 KB Output is correct
29 Correct 2 ms 1228 KB Output is correct
30 Correct 6 ms 1484 KB Output is correct
31 Correct 5 ms 1484 KB Output is correct
32 Correct 23 ms 2232 KB Output is correct
33 Correct 23 ms 2252 KB Output is correct
34 Correct 47 ms 3240 KB Output is correct
35 Correct 44 ms 3172 KB Output is correct
36 Correct 48 ms 3160 KB Output is correct
37 Correct 46 ms 3240 KB Output is correct
38 Correct 1 ms 1228 KB Output is correct
39 Correct 46 ms 3164 KB Output is correct
40 Correct 46 ms 3280 KB Output is correct
41 Correct 47 ms 3956 KB Output is correct
42 Correct 48 ms 7148 KB Output is correct