답안 #923900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923900 2024-02-08T05:39:34 Z treap_enjoyer Fancy Fence (CEOI20_fancyfence) C++17
12 / 100
1 ms 512 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast,unroll-loops")

#define ll long long
#define all(x) x.begin(), x.end()
#define ld long double
#define pii pair<int, int>
#define int long long
using namespace std;
using namespace __gnu_pbds;

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
ll bin_pow(int a, int b){
    if(!b) return 1;
    if(b & 1) return (a * bin_pow(a, b - 1)) % INF;
    else return bin_pow((a * a) % INF, b / 2);
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream cin("input.txt");
    // ofstream cout("output.txt");
    int n;
    cin >> n;
    vector<int> h(n + 1);
    vector<int> w(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> w[i];
    }
    vector<ll> dp(n + 1, 0);
    stack<pair<int, int> > st;
    st.push({0, 0});
    vector<ll> pref(n + 1);
    for(int i = 1; i <= n; i++){
        pref[i] += pref[i - 1];
        pref[i] += w[i];
    }
    vector<int> ans(n + 1, 0);
    for(int i = 1; i <= n; i++){
        while(st.top().first >= h[i]){
            st.pop();   
        }
        ll sumw = pref[i] - pref[st.top().second];
        ll x = 0;
        x = h[i];
        x *= h[i] + 1;
        x %= INF;
        x *= bin_pow(2, INF - 2);
        x %= INF;
        x *= sumw;
        x %= INF;
        dp[i] += dp[st.top().second];
        dp[i] %= INF;
        dp[i] += x;   
        dp[i] %= INF;
        ans[i] += ans[i - 1];
        ans[i] += dp[i];
        ans[i] += dp[st.top().second] * (w[i] - 1);
        ans[i] %= INF;
        x = 1;
        x *= h[i];
        x %= INF;
        x *= h[i] + 1;
        x %= INF;
        x *= bin_pow(2, INF - 2);
        x %= INF; 
        x *= sumw - w[i];
        x *= w[i] - 1;
        x %= INF;
        x %= INF;
        // cout << i << " " << x << endl;
        ans[i] += x;
        ans[i] %= INF;
        x = 1;
        x *= h[i] + 1;
        x %= INF;
        x *= h[i];
        x %= INF;
        x *= bin_pow(2, INF - 2);
        x %= INF;
        x *= w[i] - 1;
        x %= INF;
        x *= w[i];
        x %= INF;
        x *= bin_pow(2, INF - 2);
        x %= INF;
        // cout << i << " " << x << endl;
        ans[i] += x;
        ans[i] %= INF;
        st.push({h[i], i});
    }
    // cout << "goida" << endl;
    // for(int i = 1; i <= n; i++){
        // cout << dp[i] << " ";
    // }
    cout << ans[n] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 512 KB Output isn't correct
3 Halted 0 ms 0 KB -