답안 #791360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791360 2023-07-24T03:53:51 Z ttamx Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
24 ms 5540 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=1e5+5;
const ll mod=1e9+7;
const ll inv2=5e8+4;

int n;
ll h[N],w[N];
ll ans,sum;
stack<pair<ll,ll>> st;

ll calc(ll x){
    x%=mod;
    return x*(x+1)%mod*inv2%mod;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    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++){
        ans+=calc(w[i])*calc(h[i])%mod;
        ans%=mod;
        ll cnt=0;
        while(!st.empty()&&st.top().first>h[i]){
            auto [x,y]=st.top();
            st.pop();
            cnt+=y;
            cnt%=mod;
            sum+=mod-calc(x)*y%mod;
            sum%=mod;
        }
        ans+=w[i]*(sum+calc(h[i])*cnt%mod)%mod;
        ans%=mod;
        cnt+=w[i];
        st.emplace(h[i],cnt);
        sum+=calc(h[i])*cnt%mod;
        sum%=mod;
    }
    cout << ans;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:31:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   31 |             auto [x,y]=st.top();
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 11 ms 1364 KB Output is correct
4 Correct 16 ms 4304 KB Output is correct
5 Correct 17 ms 3600 KB Output is correct
6 Correct 17 ms 3152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 10 ms 1876 KB Output is correct
4 Correct 20 ms 5372 KB Output is correct
5 Correct 20 ms 5500 KB Output is correct
6 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 2 ms 596 KB Output is correct
4 Correct 10 ms 1820 KB Output is correct
5 Correct 20 ms 5456 KB Output is correct
6 Correct 20 ms 5540 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 11 ms 2900 KB Output is correct
10 Correct 20 ms 5284 KB Output is correct
11 Correct 20 ms 5320 KB Output is correct
12 Correct 0 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 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 0 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 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 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 9 ms 1364 KB Output is correct
12 Correct 16 ms 4300 KB Output is correct
13 Correct 17 ms 3668 KB Output is correct
14 Correct 16 ms 3072 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 848 KB Output is correct
17 Correct 10 ms 2900 KB Output is correct
18 Correct 20 ms 5444 KB Output is correct
19 Correct 20 ms 5492 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 3 ms 744 KB Output is correct
22 Correct 10 ms 2828 KB Output is correct
23 Correct 19 ms 5260 KB Output is correct
24 Correct 24 ms 5356 KB Output is correct
25 Correct 1 ms 212 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 580 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 10 ms 1876 KB Output is correct
33 Correct 10 ms 2016 KB Output is correct
34 Correct 20 ms 3532 KB Output is correct
35 Correct 20 ms 3540 KB Output is correct
36 Correct 20 ms 3796 KB Output is correct
37 Correct 20 ms 3708 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 21 ms 3792 KB Output is correct
40 Correct 21 ms 3696 KB Output is correct
41 Correct 24 ms 3984 KB Output is correct
42 Correct 22 ms 4564 KB Output is correct