Submission #923435

# Submission time Handle Problem Language Result Execution time Memory
923435 2024-02-07T08:32:54 Z Art_ogo Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>

#define ve vector
#define ld long double
#define ll long long
#define all(x) x.begin(), x.end()
#define fi first
#define se second

using namespace std;
using namespace chrono;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#pragma GCC optimize("Ofast")

const int MAXN = 1e5+10;
const ll mod = 1e9+7;

struct rect{
    int h, w, id;
};

inline bool comp(const rect& r1, const rect& r2){
    return r1.h < r2.h;
}

rect v[MAXN];
ll pref[MAXN];

int n;

ll binpow(ll a, ll n){
    if(n == 0)
        return 1;
    if(n & 1)
        return (a*binpow(a, n - 1))%mod;
    ll t = binpow(a, n / 2);
    return (t*t) % mod;
}

void solve(){
    cin >> n; 
    set<int> del;
    for(int i = 1; i <= n; i++)
        cin >> v[i].h;
    for(int i = 1; i <= n; i++)
        cin >> v[i].w;
    for(int i = 1; i <= n; i++)
        v[i].id = i;
    for(int i = 1; i <= n; i++)
        pref[i] = (pref[i - 1] + v[i].w) % mod;
    sort(v + 1, v + 1 + n, comp);
    ve<int> add;
    ll res = 0;
    for(int i = 1; i <= n; i++){
        auto it = del.lower_bound(v[i].id);
        ll l, r;
        if(it == del.end())
            r = n;
        else r = *it - 1;
        if(it == del.begin())
            l = 0;
        else
            l = *prev(it);
        
        ll w = (pref[r] - pref[l] + mod) % mod;
        ll pr = (w*(w - 1))%mod;
        pr = (pr*binpow(2, mod - 2)) % mod;
        pr = (pr + w) % mod;
        pr = (pr*v[i].h) % mod;
        res = (res + pr) % mod;
        add.push_back(v[i].id);
        if(i != n && v[i + 1].h != v[i].h){
            for(auto j : add)
                del.insert(j);
            add.clear();
        }
    }
    cout << res;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int T = 1;
    /* cin >> T; */
    while(T--){
        solve();
    }
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -