Submission #1080930

# Submission time Handle Problem Language Result Execution time Memory
1080930 2024-08-29T16:04:13 Z hahahaha Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
25 ms 7248 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
 
const ll mod=1e9+7;
ll w[100005],h[100005],dp[100005],qs[100005];
int n;
stack<pii> st;
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=1; i<=n; ++i) cin>>h[i];
    for (int i=1; i<=n; ++i) cin>>w[i], qs[i]=(qs[i-1]+w[i])%mod;
 
    ll ans=0;
    st.push(pii(0,0));
    for (int i=1; i<=n; ++i) {
        while (st.size() && h[st.top().first]>h[i]) st.pop();
        ll sum=(st.top().second + (h[i]*(h[i]+1)/2)%mod*(qs[i-1]-qs[st.top().first]+mod))%mod;
        dp[i]=( ((h[i]*(h[i]+1)/2)%mod) * ((w[i]*(w[i]+1)/2)%mod) + sum*w[i])%mod;
        st.push(pii(i,(sum+((h[i]*(h[i]+1)/2)%mod)*w[i])%mod));
        ans=(ans+dp[i])%mod;
    }
    cout<<ans<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 7 ms 2772 KB Output is correct
4 Correct 16 ms 5980 KB Output is correct
5 Correct 16 ms 5240 KB Output is correct
6 Correct 14 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 1112 KB Output is correct
3 Correct 9 ms 3672 KB Output is correct
4 Correct 22 ms 6996 KB Output is correct
5 Correct 18 ms 7248 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 1040 KB Output is correct
4 Correct 9 ms 3812 KB Output is correct
5 Correct 18 ms 7004 KB Output is correct
6 Correct 17 ms 7100 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 9 ms 3732 KB Output is correct
10 Correct 18 ms 6856 KB Output is correct
11 Correct 23 ms 7000 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 476 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 7 ms 2732 KB Output is correct
12 Correct 16 ms 5980 KB Output is correct
13 Correct 14 ms 5360 KB Output is correct
14 Correct 14 ms 4708 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 1116 KB Output is correct
17 Correct 9 ms 3724 KB Output is correct
18 Correct 25 ms 6992 KB Output is correct
19 Correct 17 ms 7192 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 1112 KB Output is correct
22 Correct 9 ms 3672 KB Output is correct
23 Correct 17 ms 6816 KB Output is correct
24 Correct 18 ms 6932 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 8 ms 2900 KB Output is correct
33 Correct 11 ms 2908 KB Output is correct
34 Correct 17 ms 5212 KB Output is correct
35 Correct 17 ms 5212 KB Output is correct
36 Correct 17 ms 5356 KB Output is correct
37 Correct 23 ms 5460 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 18 ms 5460 KB Output is correct
40 Correct 22 ms 5468 KB Output is correct
41 Correct 17 ms 5468 KB Output is correct
42 Correct 19 ms 6172 KB Output is correct