Submission #791413

# Submission time Handle Problem Language Result Execution time Memory
791413 2023-07-24T06:11:39 Z peteza Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
29 ms 4240 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll n, h[100005], w[100005];
stack<pll> stk;

ll mod = 1e9+7, mod6 = 166666668ll;
ll cans = 0, csum = 0;

void upd(ll&x){
    if(x<0) x += mod;
    if(x >= mod) x-=mod;
}

ll func(ll x) {
    return (x*(x+1)/2)%mod;
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    cin >> n;
    for(int i=0;i<n;i++) cin >> h[i];
    for(int i=0;i<n;i++) cin >> w[i];
    for(int i=0;i<n;i++) {
        cans += (((h[i]+1)*h[i]/2)%mod)*(((w[i]+1)*w[i]/2)%mod)%mod; upd(cans);
        ll cw = w[i];
        while(!stk.empty() && stk.top().first > h[i]) {
            cw += stk.top().second; upd(cw);
            csum -= ((1ll*func(stk.top().first)*stk.top().second) % mod);
            upd(csum);
            stk.pop();
        }
        csum += (cw-w[i])*func(h[i])%mod; upd(csum);
        cans += w[i]*csum%mod; upd(cans);
        csum += w[i]*func(h[i])%mod; upd(csum);
        stk.emplace(h[i], cw);
    }
    cout << cans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 9 ms 1960 KB Output is correct
4 Correct 20 ms 3840 KB Output is correct
5 Correct 20 ms 3276 KB Output is correct
6 Correct 18 ms 2800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 712 KB Output is correct
3 Correct 12 ms 2136 KB Output is correct
4 Correct 23 ms 3732 KB Output is correct
5 Correct 25 ms 3744 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 756 KB Output is correct
4 Correct 13 ms 2108 KB Output is correct
5 Correct 29 ms 3736 KB Output is correct
6 Correct 23 ms 3740 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 12 ms 2104 KB Output is correct
10 Correct 23 ms 3752 KB Output is correct
11 Correct 24 ms 3704 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 10 ms 1976 KB Output is correct
12 Correct 18 ms 3928 KB Output is correct
13 Correct 18 ms 3276 KB Output is correct
14 Correct 22 ms 2788 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 828 KB Output is correct
17 Correct 12 ms 2592 KB Output is correct
18 Correct 24 ms 4240 KB Output is correct
19 Correct 24 ms 4172 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 852 KB Output is correct
22 Correct 12 ms 2596 KB Output is correct
23 Correct 23 ms 4204 KB Output is correct
24 Correct 26 ms 4168 KB Output is correct
25 Correct 0 ms 324 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 12 ms 1876 KB Output is correct
33 Correct 14 ms 1860 KB Output is correct
34 Correct 25 ms 2636 KB Output is correct
35 Correct 25 ms 2636 KB Output is correct
36 Correct 26 ms 2620 KB Output is correct
37 Correct 25 ms 2536 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 25 ms 2624 KB Output is correct
40 Correct 26 ms 2616 KB Output is correct
41 Correct 29 ms 2760 KB Output is correct
42 Correct 25 ms 3412 KB Output is correct