답안 #558059

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558059 2022-05-06T16:08:25 Z Tenis0206 Fancy Fence (CEOI20_fancyfence) C++11
100 / 100
32 ms 6128 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int Mod = 1e9 + 7;

int n;

int h[100005],w[100005];
int sp[100005];

signed main()
{
    ios::sync_with_stdio(false);
    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];
        sp[i] = (sp[i-1] + w[i]) % Mod;
    }
    stack<int> st,st_sum;
    st.push(0);
    st_sum.push(0);
    long long sum = 0, rez = 0;
    for(int i=1;i<=n;i++)
    {
        while(h[i]<=h[st.top()])
        {
            sum = (sum - st_sum.top() + Mod) % Mod;
            st_sum.pop();
            st.pop();
        }

        sum += (sp[i-1] - sp[st.top()] + Mod) % Mod * (h[i] * (h[i] + 1) / 2 % Mod) % Mod;
        sum %= Mod;

        rez += 1LL * sum * w[i] % Mod;
        rez %= Mod;
        rez += w[i] * (w[i] + 1) / 2 % Mod * (h[i] * (h[i]+1) / 2 % Mod) % Mod;
        rez %= Mod;

        sum += w[i] * (h[i] * (h[i] + 1) / 2 % Mod) % Mod;
        sum %= Mod;

        int c_sum = (sp[i] - sp[st.top()] + Mod) % Mod * (h[i] * (h[i] + 1) / 2 % Mod) % Mod;
        st_sum.push(c_sum);
        st.push(i);
    }
    cout<<rez<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 10 ms 2012 KB Output is correct
4 Correct 19 ms 3736 KB Output is correct
5 Correct 20 ms 3796 KB Output is correct
6 Correct 20 ms 3708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 12 ms 2388 KB Output is correct
4 Correct 26 ms 4272 KB Output is correct
5 Correct 32 ms 4304 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 5 ms 724 KB Output is correct
4 Correct 19 ms 2376 KB Output is correct
5 Correct 26 ms 4264 KB Output is correct
6 Correct 29 ms 4244 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 852 KB Output is correct
9 Correct 13 ms 2832 KB Output is correct
10 Correct 26 ms 5968 KB Output is correct
11 Correct 27 ms 5964 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 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 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 10 ms 2004 KB Output is correct
12 Correct 23 ms 3724 KB Output is correct
13 Correct 19 ms 3796 KB Output is correct
14 Correct 19 ms 3784 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 720 KB Output is correct
17 Correct 13 ms 2448 KB Output is correct
18 Correct 26 ms 4580 KB Output is correct
19 Correct 29 ms 4636 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 836 KB Output is correct
22 Correct 15 ms 2772 KB Output is correct
23 Correct 26 ms 6036 KB Output is correct
24 Correct 26 ms 6128 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 12 ms 2292 KB Output is correct
33 Correct 12 ms 2444 KB Output is correct
34 Correct 23 ms 4360 KB Output is correct
35 Correct 23 ms 4340 KB Output is correct
36 Correct 26 ms 4556 KB Output is correct
37 Correct 25 ms 4516 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 23 ms 4560 KB Output is correct
40 Correct 24 ms 4536 KB Output is correct
41 Correct 24 ms 4684 KB Output is correct
42 Correct 26 ms 5324 KB Output is correct