Submission #945589

# Submission time Handle Problem Language Result Execution time Memory
945589 2024-03-14T05:20:19 Z beepbeepsheep Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
46 ms 21924 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define iii tuple<ll,ll,ll>

const ll inf=1e15;
const ll maxn=1e5+5;
const ll mod=1e9+7;
ll h[maxn],w[maxn];
ll ans;
struct node{
    ll s,e,m;
    ii val;
    node *l,*r;
    node (ll _s, ll _e){
        s=_s,e=_e,m=(s+e)>>1,val={0,s};
        if (s!=e) l=new node(s,m),r=new node(m+1,e);
    }
    void upd(ll x, ll v){
        if (s==e){
            val.first=v;
            return;
        }
        if (x>m) r->upd(x,v);
        else l->upd(x,v);
        val=min(l->val,r->val);
    }
    ii query(ll x, ll y){
        if (x<=s && e<=y) return val;
        if (x>m) return r->query(x,y);
        if (y<=m) return l->query(x,y);
        return min(l->query(x,y),r->query(x,y));
    }
}*root;
ll tri(ll x){
    x%=mod;
    return (x*(x+1)/2)%mod;
}
void dnc(ll l, ll r, ll par){
    if (l>r) return;
    ll val,pos;
    tie(val,pos)=root->query(l,r);
    val-=par;
    ans+=(val*par%mod+tri(val))%mod*tri(w[r]-w[l-1]);
    ans%=mod;
    val+=par;
    dnc(l,pos-1,val);
    dnc(pos+1,r,val);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    root=new node(1,n);
    for (int i=1;i<=n;i++){
        cin>>h[i];
        root->upd(i,h[i]);
    }
    for (int i=1;i<=n;i++) cin>>w[i],w[i]+=w[i-1];
    dnc(1,n,0);
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 20 ms 7260 KB Output is correct
4 Correct 37 ms 15444 KB Output is correct
5 Correct 40 ms 15688 KB Output is correct
6 Correct 37 ms 15440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 4 ms 1628 KB Output is correct
3 Correct 20 ms 7292 KB Output is correct
4 Correct 46 ms 16460 KB Output is correct
5 Correct 40 ms 16464 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 4 ms 1628 KB Output is correct
4 Correct 19 ms 7260 KB Output is correct
5 Correct 40 ms 16468 KB Output is correct
6 Correct 40 ms 16468 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 5 ms 1884 KB Output is correct
9 Correct 19 ms 8508 KB Output is correct
10 Correct 45 ms 16376 KB Output is correct
11 Correct 40 ms 16220 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 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
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 18 ms 7504 KB Output is correct
12 Correct 38 ms 15440 KB Output is correct
13 Correct 38 ms 15452 KB Output is correct
14 Correct 38 ms 15540 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 4 ms 1880 KB Output is correct
17 Correct 19 ms 8404 KB Output is correct
18 Correct 40 ms 16468 KB Output is correct
19 Correct 43 ms 16520 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 4 ms 2012 KB Output is correct
22 Correct 21 ms 8284 KB Output is correct
23 Correct 39 ms 16208 KB Output is correct
24 Correct 40 ms 16208 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 472 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 4 ms 1944 KB Output is correct
31 Correct 4 ms 1884 KB Output is correct
32 Correct 19 ms 8284 KB Output is correct
33 Correct 21 ms 8268 KB Output is correct
34 Correct 40 ms 16120 KB Output is correct
35 Correct 40 ms 16208 KB Output is correct
36 Correct 43 ms 16452 KB Output is correct
37 Correct 42 ms 16468 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 42 ms 16452 KB Output is correct
40 Correct 42 ms 16468 KB Output is correct
41 Correct 44 ms 17576 KB Output is correct
42 Correct 43 ms 21924 KB Output is correct