답안 #577543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577543 2022-06-15T04:14:52 Z talant117408 Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define long                unsigned long 
#define pb                  push_back
#define mp                  make_pair
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define lb                  lower_bound
#define ub                  upper_bound
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'

void solve() {
    int n;
    cin >> n;
    
    ll mod = 1e9+7;
    function <ll(ll, ll)> add = [&](ll a, ll b) {
        return ((a+b)%mod+mod)%mod;
    };
    function <ll(ll, ll)> mult = [&](ll a, ll b) {
        return ((a*b)%mod+mod)%mod;
    };
    function <ll(ll, ll)> binpow = [&](ll a, ll b) {
        ll res = 1;
        while (b) {
            if (b&1) res = mult(res, a);
            a = mult(a, a);
            b >>= 1;
        }
        return res;
    };
    ll inv2 = binpow(2, mod-2);
    function <ll(ll)> calc = [&](ll n) {
        return mult(mult(n, n+1), inv2);
    };
    
    vector <ll> h(n), w(n);
    for (auto &to : h) cin >> to;
    for (auto &to : w) cin >> to;
    stack <pll> heights;
    ll ans = 0, sum = 0;
    for (int i = 0; i < n; i++) {
        ll left = 0;
        while (sz(heights) && heights.top().first >= h[i]) {
            auto v = heights.top(); heights.pop();
            left += v.second;
            sum = add(sum, -mult(calc(v.first), v.second));
        }
        ans = add(ans, -mult(calc(h[i]), calc(left)));
        ans = add(ans, mult(calc(h[i]), calc(w[i]+left)));
        ans = add(ans, mult(sum, w[i]+left));
        sum = add(sum, mult(calc(h[i]), w[i]+left));
        heights.push(mp(h[i], w[i]+left));
    }
    cout << ans << endl;
}

int main() {
    do_not_disturb
    
    int t = 1;
    //~ cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -