Submission #1008287

# Submission time Handle Problem Language Result Execution time Memory
1008287 2024-06-26T08:54:13 Z devariaota Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
63 ms 11208 KB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<ll,ll>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define freeopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define pb push_back
#define mk make_pair
#define ll long long
#define foor(x,vec) for(auto x:vec ){cout<<x<<" ";}
#define fi first
#define se second
#define MAXN 700069
#define lld long double
#define cha ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ffl fflush(stdout)
#define sst string
#define pii pair<ll,ll>
ll mvx[]={0,0,-1,1};
ll mvy[]={1,-1,0,0};
ll n,q;
ll a,b;
ll h[MAXN],w[MAXN];
ll ps[MAXN];
ll dp[MAXN];
ll idx[MAXN];
const ll mod =1e9+7;
ll add(ll x, ll y) {
    ll res=(x+y+mod)%mod;
    return res;
}
 
 
ll cal(ll x) {
    return (ll)((1ll * x * (x + 1) / 2) % mod);
}
ll mult(ll x, ll y) {
    return (ll)((1ll * x * y) % mod);
}
 
 
int main(){
    cin>>n;
    REP(i,1,n)cin>>h[i];
    REP(i,1,n)cin>>w[i];
    REP(i,1,n){
        ps[i]=ps[i-1]+w[i];
        ps[i]%=mod;
    }
    vector <ll> vec;
    vec.pb(0);
    for(ll i = 1; i <= n; i++) {
        while(vec.size() && h[i] < h[vec.back()]) {
            vec.pop_back();
        }
        assert(vec.size());
        idx[i] = vec.back();
        vec.pb(i);
    }
    ll ans=0;
    REP(i,1,n){
        dp[i] = add(dp[idx[i]], mult((ps[i]-ps[idx[i]]+mod)%mod, cal(h[i])));
        ll val = mult(dp[idx[i]], w[i]);
        // ini buat sebelumnya
        val = add(val, mult(cal(w[i] ), cal(h[i] )));
        val = add(val, mult( (ps[i - 1] - ps[idx[i]]+mod)%mod, mult(w[i], cal(h[i]))));
        // ini buat diantara
        // ini buat sendiri
        ans = add(ans, val);
    }
    ans=(ans+mod)%mod;
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 16 ms 9688 KB Output is correct
4 Correct 35 ms 9676 KB Output is correct
5 Correct 40 ms 9268 KB Output is correct
6 Correct 32 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 7 ms 4956 KB Output is correct
3 Correct 24 ms 9940 KB Output is correct
4 Correct 55 ms 11208 KB Output is correct
5 Correct 45 ms 11208 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 5 ms 4792 KB Output is correct
4 Correct 30 ms 8224 KB Output is correct
5 Correct 46 ms 9772 KB Output is correct
6 Correct 48 ms 9672 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 5 ms 4988 KB Output is correct
9 Correct 24 ms 9940 KB Output is correct
10 Correct 48 ms 9768 KB Output is correct
11 Correct 48 ms 9776 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2492 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 15 ms 4272 KB Output is correct
12 Correct 42 ms 6188 KB Output is correct
13 Correct 35 ms 7884 KB Output is correct
14 Correct 31 ms 5756 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 5 ms 2908 KB Output is correct
17 Correct 22 ms 6352 KB Output is correct
18 Correct 63 ms 8228 KB Output is correct
19 Correct 45 ms 6340 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 5 ms 2816 KB Output is correct
22 Correct 25 ms 6456 KB Output is correct
23 Correct 41 ms 6344 KB Output is correct
24 Correct 53 ms 6340 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 2 ms 4536 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 6 ms 2744 KB Output is correct
31 Correct 7 ms 4700 KB Output is correct
32 Correct 25 ms 5980 KB Output is correct
33 Correct 30 ms 5980 KB Output is correct
34 Correct 43 ms 7348 KB Output is correct
35 Correct 42 ms 7456 KB Output is correct
36 Correct 46 ms 7508 KB Output is correct
37 Correct 43 ms 5540 KB Output is correct
38 Correct 0 ms 2392 KB Output is correct
39 Correct 44 ms 7504 KB Output is correct
40 Correct 46 ms 7512 KB Output is correct
41 Correct 58 ms 7520 KB Output is correct
42 Correct 46 ms 6088 KB Output is correct