Submission #502437

# Submission time Handle Problem Language Result Execution time Memory
502437 2022-01-06T02:21:38 Z Fireball0424 Fancy Fence (CEOI20_fancyfence) C++14
12 / 100
1 ms 332 KB
#include <bits/stdc++.h>
#define int long long
#define fr first
#define sc second
#define pii pair<int,int>
using namespace std;

const int mod = 1e9 + 7;

int modpow(int a, int b){
    if(b == 0) return 1;
    int res = modpow(a, b / 2);
    res = (res * res) % mod;
    if(b & 1) res = (res * a) % mod;
    return res;
}

int cal(int x){
    return (x * (x + 1) / 2) % mod;
}

void solve(){
    int n;
    cin >> n;
    vector<int> h(n + 1, 0), w(n + 1, 0);
    for(int i = 1; i <= n; ++i) cin >> h[i];
    for(int i = 1; i <= n; ++i) cin >> w[i];
    stack<int> stk;
    stk.push(0);
    int ans = 0;
    vector<int> dp(n + 1, 0), pre(n + 1, 0);
    for(int i = 1; i <= n; ++i) pre[i] = pre[i-1] + w[i];
    for(int i = 1; i <= n; ++i) {
        while (h[stk.top()] >= h[i]) stk.pop();
        dp[i] = dp[stk.top()] + cal(h[i]) * (pre[i] - pre[stk.top()]);
        ans = (ans + dp[stk.top()] * w[i]) % mod;
        ans = (ans + cal(h[i]) * (pre[i - 1] - pre[stk.top()]) * w[i]) % mod;
        ans = (ans + cal(h[i]) * cal(w[i])) % mod;
        stk.push(i);
    }
    cout << ans << endl;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("bbreeds.in", "r");
    //freopen("bbreeds.out", "w");
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct