Submission #946373

# Submission time Handle Problem Language Result Execution time Memory
946373 2024-03-14T14:49:12 Z hmm789 Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
22 ms 4440 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000000000000000
#define MOD 1000000007

struct node {
    int s, e, m, sm, mn;
    node *l, *r;
    node(int _s, int _e) {
        s = _s, e = _e, m = (s+e)/2, sm = mn = 0;
        if(s != e) {
            l = new node(s, m);
            r = new node(m+1, e);
        }
    }
    void update(int x, int val) {
        if(s == e) {sm = mn = val; return;}
        else if(x > m) r->update(x, val);
        else l->update(x, val);
        sm = (l->sm + r->sm) % MOD;
        mn = min(l->mn, r->mn);
    }
    int rsum(int x, int y) {
        if(x > y) return 0;
        if(x <= s && e <= y) return sm;
        else if(x > m) return r->rsum(x, y);
        else if(y <= m) return l->rsum(x, y);
        else return (l->rsum(x, y) + r->rsum(x, y)) % MOD;
    }
    int rmin(int x, int y) {
        if(x > y) return -INF;
        if(x <= s && e <= y) return mn;
        else if(x > m) return r->rmin(x, y);
        else if(y <= m) return l->rmin(x, y);
        else return min(l->rmin(x, y), r->rmin(x, y));
    }
} *rh, *rw;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, ans = 0, sm = 0;
    cin >> n;
    int h[n], w[n];
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < n; i++) cin >> w[i];
    stack<tuple<int, int, int>> s;
    for(int i = 0; i < n; i++) {
        int num = (h[i]+1)*h[i]/2 % MOD, num2 = (w[i]+1)*w[i]/2 % MOD;
        ans += num * num2 % MOD;
        ans %= MOD;
        int nnw = w[i], nv;
        while(s.size() && get<0>(s.top()) >= h[i]) {
            int nh, nw, val;
            tie(nh, nw, val) = s.top();
            s.pop();
            ans += w[i]*nw % MOD * num % MOD;
            ans %= MOD;
            sm = (sm - val + MOD) % MOD;
            nnw += nw;
        }
        ans += w[i]*sm % MOD;
        ans %= MOD;
        nv = num * nnw % MOD;
        sm += nv;
        sm %= MOD;
        nnw %= MOD;
        s.push({h[i], nnw, nv});
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 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 0 ms 348 KB Output is correct
3 Correct 1 ms 344 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 0 ms 348 KB Output is correct
3 Correct 8 ms 1232 KB Output is correct
4 Correct 14 ms 1884 KB Output is correct
5 Correct 14 ms 2012 KB Output is correct
6 Correct 14 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 9 ms 1112 KB Output is correct
4 Correct 18 ms 1884 KB Output is correct
5 Correct 18 ms 1884 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 9 ms 1228 KB Output is correct
5 Correct 18 ms 1884 KB Output is correct
6 Correct 18 ms 1880 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 9 ms 1876 KB Output is correct
10 Correct 22 ms 4312 KB Output is correct
11 Correct 18 ms 4440 KB Output is correct
12 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 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
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 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 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 7 ms 1116 KB Output is correct
12 Correct 14 ms 1884 KB Output is correct
13 Correct 18 ms 2268 KB Output is correct
14 Correct 20 ms 1884 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 608 KB Output is correct
17 Correct 9 ms 1116 KB Output is correct
18 Correct 17 ms 2012 KB Output is correct
19 Correct 18 ms 1884 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 9 ms 1628 KB Output is correct
23 Correct 17 ms 4188 KB Output is correct
24 Correct 18 ms 4320 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 2 ms 600 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 9 ms 1232 KB Output is correct
33 Correct 9 ms 1116 KB Output is correct
34 Correct 18 ms 2016 KB Output is correct
35 Correct 17 ms 1880 KB Output is correct
36 Correct 18 ms 1880 KB Output is correct
37 Correct 18 ms 1880 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 18 ms 1884 KB Output is correct
40 Correct 18 ms 2008 KB Output is correct
41 Correct 18 ms 2140 KB Output is correct
42 Correct 18 ms 3164 KB Output is correct