답안 #793222

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793222 2023-07-25T16:09:08 Z SlavicG Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
35 ms 25816 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

#define int long long
const int N = 1e5 + 5, mod = 1e9 + 7, K = 17;
int ans = 0;
int jump[N][K], h[N], n, p[N], w[N];
int merge(int i, int j) { return h[i] < h[j] ? i : j; }
int query(int l, int r) {
    int j = 31 - __builtin_clz(r - l + 1);
    return merge(jump[l][j], jump[r - (1 << j) + 1][j]);
}

void rec(int l, int r) {
    if(l > r) return;
    int i = query(l, r);
    int canh = h[i] * (h[i] + 1) / 2 % mod;
    
    int val = (p[i] - (l ? p[l - 1] : 0)) % mod;
    val *= (p[r] - p[i]) % mod;
    val %= mod;
    if(i > l) {
        val += (p[i - 1] % mod - (l ? p[l - 1] : 0) % mod + mod) % mod * w[i] % mod;
    }
    val += w[i] * (w[i] + 1) / 2 % mod;
    val %= mod;
    ans += val * canh % mod;
    ans %= mod;
    rec(l, i - 1);
    rec(i + 1, r);
}

void solve() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> h[i];
        jump[i][0] = i;
    }
    for(int i = 0; i < n; ++i) {
        cin >> w[i];
        p[i] = w[i] + (i ? p[i - 1] : 0);
    }
    for(int j = 1; j < K; ++j) {
        for(int i = 0; i + (1 << j) <= n; ++i) {
            jump[i][j] = merge(jump[i][j - 1], jump[i + (1 << (j - 1))][j - 1]);
        }
    }
    rec(0, n - 1);
    cout << ans << "\n";
}   
 
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Correct 13 ms 10280 KB Output is correct
4 Correct 31 ms 23368 KB Output is correct
5 Correct 29 ms 20232 KB Output is correct
6 Correct 28 ms 17872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 3 ms 2856 KB Output is correct
3 Correct 16 ms 13020 KB Output is correct
4 Correct 34 ms 25676 KB Output is correct
5 Correct 34 ms 25704 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 16 ms 13004 KB Output is correct
5 Correct 35 ms 25684 KB Output is correct
6 Correct 34 ms 25816 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 3 ms 2004 KB Output is correct
9 Correct 14 ms 11460 KB Output is correct
10 Correct 28 ms 17716 KB Output is correct
11 Correct 29 ms 17788 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 480 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 13 ms 10268 KB Output is correct
12 Correct 29 ms 23372 KB Output is correct
13 Correct 30 ms 20196 KB Output is correct
14 Correct 29 ms 17880 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 3 ms 2780 KB Output is correct
17 Correct 16 ms 12988 KB Output is correct
18 Correct 32 ms 25676 KB Output is correct
19 Correct 33 ms 25808 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 3 ms 2004 KB Output is correct
22 Correct 15 ms 11448 KB Output is correct
23 Correct 27 ms 17740 KB Output is correct
24 Correct 28 ms 17836 KB Output is correct
25 Correct 0 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 3 ms 2000 KB Output is correct
31 Correct 3 ms 2096 KB Output is correct
32 Correct 14 ms 9084 KB Output is correct
33 Correct 14 ms 9120 KB Output is correct
34 Correct 30 ms 17688 KB Output is correct
35 Correct 29 ms 17700 KB Output is correct
36 Correct 31 ms 17800 KB Output is correct
37 Correct 30 ms 17868 KB Output is correct
38 Correct 1 ms 328 KB Output is correct
39 Correct 31 ms 17788 KB Output is correct
40 Correct 28 ms 17892 KB Output is correct
41 Correct 29 ms 18672 KB Output is correct
42 Correct 31 ms 21712 KB Output is correct