답안 #946318

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946318 2024-03-14T13:45:32 Z hmm789 Fancy Fence (CEOI20_fancyfence) C++14
0 / 100
2 ms 604 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 <= 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;
    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];
    rh = new node(0, n);
    rw = new node(0, n);
    for(int i = 0; i < n; i++) {
        rh->update(i, h[i]);
        rw->update(i, w[i]);
    }
    rh->update(n, INF);
    for(int i = 0; i < n; i++) {
        int num = h[i]*(h[i]+1)/2 % MOD, num2 = w[i]*(w[i]+1)/2 % MOD;
        ans += num*num2 % MOD;
        ans %= MOD;
        int l = 0, r = i, m;
        while(l < r) {
            m = (l+r)/2;
            if(rh->rmin(m, i) < h[i]) l = m+1;
            else r = m;
        }
        int idx = l;
        num2 = num * w[i] % MOD;
        ans += num * rw->rsum(idx, i-1) % MOD;
        ans %= MOD;
        l = i+1; r = n;
        while(l < r) {
            m = (l+r)/2;
            if(rh->rmin(i+1, m) <= h[i]) r = m;
            else l = m+1;
        }
        idx = l;
        num2 = num * w[i] % MOD;
        ans += num * rw->rsum(i+1, idx-1) % MOD;
        ans %= MOD;
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 2 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 2 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Incorrect 2 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Incorrect 2 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 2 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -