Submission #871573

# Submission time Handle Problem Language Result Execution time Memory
871573 2023-11-11T06:17:46 Z Trisanu_Das Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
21 ms 7260 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 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 8 ms 3932 KB Output is correct
4 Correct 15 ms 5928 KB Output is correct
5 Correct 15 ms 5204 KB Output is correct
6 Correct 14 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 2908 KB Output is correct
3 Correct 9 ms 4700 KB Output is correct
4 Correct 18 ms 7176 KB Output is correct
5 Correct 19 ms 7260 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2536 KB Output is correct
3 Correct 3 ms 2908 KB Output is correct
4 Correct 10 ms 4684 KB Output is correct
5 Correct 19 ms 6996 KB Output is correct
6 Correct 18 ms 7180 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 3 ms 2904 KB Output is correct
9 Correct 10 ms 4676 KB Output is correct
10 Correct 21 ms 7000 KB Output is correct
11 Correct 19 ms 6964 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2524 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2516 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 8 ms 3928 KB Output is correct
12 Correct 15 ms 5980 KB Output is correct
13 Correct 18 ms 5192 KB Output is correct
14 Correct 14 ms 4696 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 3 ms 2908 KB Output is correct
17 Correct 9 ms 4676 KB Output is correct
18 Correct 19 ms 6996 KB Output is correct
19 Correct 21 ms 7260 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 2 ms 2904 KB Output is correct
22 Correct 10 ms 4700 KB Output is correct
23 Correct 18 ms 6856 KB Output is correct
24 Correct 18 ms 7088 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 11 ms 3932 KB Output is correct
33 Correct 9 ms 3932 KB Output is correct
34 Correct 17 ms 5212 KB Output is correct
35 Correct 17 ms 5212 KB Output is correct
36 Correct 18 ms 5272 KB Output is correct
37 Correct 18 ms 5468 KB Output is correct
38 Correct 1 ms 2520 KB Output is correct
39 Correct 18 ms 5444 KB Output is correct
40 Correct 18 ms 5428 KB Output is correct
41 Correct 18 ms 5456 KB Output is correct
42 Correct 18 ms 6132 KB Output is correct