제출 #791413

#제출 시각아이디문제언어결과실행 시간메모리
791413petezaFancy Fence (CEOI20_fancyfence)C++14
100 / 100
29 ms4240 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll n, h[100005], w[100005];
stack<pll> stk;

ll mod = 1e9+7, mod6 = 166666668ll;
ll cans = 0, csum = 0;

void upd(ll&x){
    if(x<0) x += mod;
    if(x >= mod) x-=mod;
}

ll func(ll x) {
    return (x*(x+1)/2)%mod;
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    cin >> n;
    for(int i=0;i<n;i++) cin >> h[i];
    for(int i=0;i<n;i++) cin >> w[i];
    for(int i=0;i<n;i++) {
        cans += (((h[i]+1)*h[i]/2)%mod)*(((w[i]+1)*w[i]/2)%mod)%mod; upd(cans);
        ll cw = w[i];
        while(!stk.empty() && stk.top().first > h[i]) {
            cw += stk.top().second; upd(cw);
            csum -= ((1ll*func(stk.top().first)*stk.top().second) % mod);
            upd(csum);
            stk.pop();
        }
        csum += (cw-w[i])*func(h[i])%mod; upd(csum);
        cans += w[i]*csum%mod; upd(cans);
        csum += w[i]*func(h[i])%mod; upd(csum);
        stk.emplace(h[i], cw);
    }
    cout << cans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...