답안 #445107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445107 2021-07-16T13:03:02 Z KULIKOLD Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
34 ms 5408 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
const int DIM = 2E5+7;
const ll MOD = 1E9+7;
ll W[DIM],H[DIM];
int solve(){
    ll res = 0,sum = 0;
    stack<pair<ll,ll> > S;
    int n;
    cin>>n;
    for(int i = 1;i<=n;++i)
        cin>>H[i];
    for(int i = 1;i<=n;++i)
        cin>>W[i];
    for(int i = 1;i<=n;++i){
        ll h = H[i],w = W[i];
        ll cur = 0;
        while(!S.empty() && S.top().first>=h){
            cur+=S.top().second;
            sum= (sum-S.top().first*(S.top().first+1)/2%MOD*S.top().second)%MOD;
            sum = (sum+h*(h+1)/2%MOD*S.top().second)%MOD;
            S.pop();
        }
        res = (res+w*sum)%MOD;
        ll mu = h*(h+1)/2%MOD;
        res = (res+w*(w+1)/2%MOD*mu%MOD)%MOD;
        cur+=w;
        sum = (sum+h*(h+1)/2%MOD*w)%MOD;
        S.push({h,cur%MOD});
    }
    if (res<0)res+=MOD;
    cout<<res<<endl;
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    t = 1;
    while(t--)
        assert(solve());
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 12 ms 1612 KB Output is correct
4 Correct 23 ms 3020 KB Output is correct
5 Correct 24 ms 2952 KB Output is correct
6 Correct 23 ms 3012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 360 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 15 ms 2008 KB Output is correct
4 Correct 28 ms 3268 KB Output is correct
5 Correct 32 ms 3204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 15 ms 2064 KB Output is correct
5 Correct 28 ms 3572 KB Output is correct
6 Correct 34 ms 3528 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 3 ms 844 KB Output is correct
9 Correct 16 ms 2404 KB Output is correct
10 Correct 29 ms 5172 KB Output is correct
11 Correct 29 ms 5060 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 12 ms 1672 KB Output is correct
12 Correct 25 ms 3000 KB Output is correct
13 Correct 23 ms 3012 KB Output is correct
14 Correct 23 ms 2992 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 14 ms 1996 KB Output is correct
18 Correct 30 ms 3768 KB Output is correct
19 Correct 32 ms 3744 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 3 ms 840 KB Output is correct
22 Correct 16 ms 2364 KB Output is correct
23 Correct 28 ms 5248 KB Output is correct
24 Correct 28 ms 5408 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 328 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 4 ms 588 KB Output is correct
32 Correct 14 ms 1856 KB Output is correct
33 Correct 15 ms 1996 KB Output is correct
34 Correct 31 ms 3636 KB Output is correct
35 Correct 27 ms 3588 KB Output is correct
36 Correct 29 ms 3796 KB Output is correct
37 Correct 29 ms 3792 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 29 ms 3820 KB Output is correct
40 Correct 29 ms 3788 KB Output is correct
41 Correct 29 ms 3916 KB Output is correct
42 Correct 29 ms 4540 KB Output is correct