Submission #609297

# Submission time Handle Problem Language Result Execution time Memory
609297 2022-07-27T13:26:33 Z 1bin Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
30 ms 4180 KB
#include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e5 + 5;
const ll mod = 1e9 + 7;
ll n, h[NMAX], w[NMAX], ans, x, ix, mxh, wd;
stack<int> st;

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> h[i];
    for(int i = 1; i <= n; i++) cin >> w[i], w[i] = (w[i] + w[i - 1]) % mod;
    st.emplace(0);
    for(int i = 1; i <= n; i++){
        while(st.size() >= 2 && h[st.top()] > h[i]){
            ix = st.top(); st.pop();
            mxh = max(h[st.top()], h[i]);
            wd = w[ix] - w[st.top()]; wd = (wd % mod + mod) % mod;
            ans += (h[ix] * (h[ix] + 1) / 2 - mxh * (mxh + 1) / 2) % mod * (wd * (wd + 1) / 2 % mod); ans %= mod;
            if(h[st.top()] > h[i]) w[st.top()] = w[ix];
        }
        if(h[st.top()] == h[i]) st.pop();
        st.emplace(i);
    }
    
    while(st.size() >= 2){
        ix = st.top(); st.pop();
        wd = w[n] - w[st.top()]; wd = (wd % mod + mod) % mod;
        ans += (h[ix] * (h[ix] + 1) / 2 - h[st.top()] * (h[st.top()] + 1) / 2) % mod * (wd * (wd + 1) / 2 % mod); ans %= mod;
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 9 ms 1628 KB Output is correct
4 Correct 15 ms 2764 KB Output is correct
5 Correct 22 ms 2764 KB Output is correct
6 Correct 23 ms 2720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 10 ms 2032 KB Output is correct
4 Correct 20 ms 3788 KB Output is correct
5 Correct 25 ms 3788 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 584 KB Output is correct
4 Correct 10 ms 1960 KB Output is correct
5 Correct 22 ms 3792 KB Output is correct
6 Correct 24 ms 3856 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 12 ms 2132 KB Output is correct
10 Correct 22 ms 4068 KB Output is correct
11 Correct 30 ms 4132 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 356 KB Output is correct
10 Correct 1 ms 340 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 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1620 KB Output is correct
12 Correct 15 ms 2944 KB Output is correct
13 Correct 26 ms 3020 KB Output is correct
14 Correct 17 ms 3016 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 11 ms 1984 KB Output is correct
18 Correct 28 ms 3716 KB Output is correct
19 Correct 25 ms 3912 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 18 ms 2156 KB Output is correct
23 Correct 22 ms 4068 KB Output is correct
24 Correct 23 ms 4180 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 11 ms 1876 KB Output is correct
33 Correct 13 ms 2004 KB Output is correct
34 Correct 23 ms 3604 KB Output is correct
35 Correct 22 ms 3604 KB Output is correct
36 Correct 22 ms 3788 KB Output is correct
37 Correct 21 ms 3740 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 23 ms 3792 KB Output is correct
40 Correct 25 ms 3780 KB Output is correct
41 Correct 27 ms 3856 KB Output is correct
42 Correct 27 ms 4072 KB Output is correct