Submission #534886

# Submission time Handle Problem Language Result Execution time Memory
534886 2022-03-09T05:45:44 Z mjhmjh1104 Fancy Fence (CEOI20_fancyfence) C++17
43 / 100
1000 ms 3268 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)1e9, -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 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 22 ms 2252 KB Output is correct
4 Correct 50 ms 3188 KB Output is correct
5 Correct 45 ms 3236 KB Output is correct
6 Correct 43 ms 3240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 5 ms 1484 KB Output is correct
3 Correct 26 ms 2176 KB Output is correct
4 Correct 49 ms 3176 KB Output is correct
5 Execution timed out 1083 ms 3168 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 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 6 ms 1504 KB Output is correct
4 Correct 27 ms 2288 KB Output is correct
5 Correct 51 ms 3144 KB Output is correct
6 Execution timed out 1085 ms 3132 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 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 1252 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 2 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 2 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 2 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 2 ms 1228 KB Output is correct
4 Correct 3 ms 1228 KB Output is correct
5 Correct 1 ms 1356 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 1 ms 1228 KB Output is correct
10 Correct 2 ms 1228 KB Output is correct
11 Correct 21 ms 2288 KB Output is correct
12 Correct 46 ms 3240 KB Output is correct
13 Correct 47 ms 3140 KB Output is correct
14 Correct 46 ms 3140 KB Output is correct
15 Correct 3 ms 1228 KB Output is correct
16 Correct 7 ms 1472 KB Output is correct
17 Correct 25 ms 2172 KB Output is correct
18 Correct 51 ms 3268 KB Output is correct
19 Execution timed out 1082 ms 3140 KB Time limit exceeded
20 Halted 0 ms 0 KB -