답안 #534880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534880 2022-03-09T05:37:24 Z mjhmjh1104 Fancy Fence (CEOI20_fancyfence) C++17
43 / 100
1000 ms 3252 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 x = (1LL * h[m] * (h[m] + 1) / 2 % MOD - 1LL * curr * (curr + 1) / 2 % MOD + MOD) % MOD;
    res = (res + 1LL * x * (1LL * get(l, r) * (get(l, r) + 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:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
fancyfence.cpp:35:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     for (int i = 0; i < n; i++) scanf("%d", h + i);
      |                                 ~~~~~^~~~~~~~~~~~~
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", w + i);
      |                                 ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 2 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 29 ms 2252 KB Output is correct
4 Correct 51 ms 3240 KB Output is correct
5 Correct 55 ms 3240 KB Output is correct
6 Correct 51 ms 3236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1228 KB Output is correct
2 Correct 6 ms 1512 KB Output is correct
3 Correct 26 ms 2288 KB Output is correct
4 Correct 58 ms 3192 KB Output is correct
5 Execution timed out 1088 ms 3252 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 9 ms 1440 KB Output is correct
4 Correct 26 ms 2292 KB Output is correct
5 Correct 55 ms 3220 KB Output is correct
6 Execution timed out 1055 ms 3148 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 2 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 2 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 3 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 2 ms 1228 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 2 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 2 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 2 ms 1228 KB Output is correct
11 Correct 25 ms 2232 KB Output is correct
12 Correct 49 ms 3156 KB Output is correct
13 Correct 47 ms 3148 KB Output is correct
14 Correct 45 ms 3132 KB Output is correct
15 Correct 2 ms 1228 KB Output is correct
16 Correct 6 ms 1484 KB Output is correct
17 Correct 38 ms 2232 KB Output is correct
18 Correct 73 ms 3156 KB Output is correct
19 Execution timed out 1086 ms 3220 KB Time limit exceeded
20 Halted 0 ms 0 KB -