답안 #442788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442788 2021-07-09T04:59:35 Z flashhh Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
97 ms 15236 KB
#include <bits/stdc++.h>
#define nmax 100010
#define ll long long

const int oo=1e9+7;

using namespace std;

int n,h[nmax],rmq[nmax][25];
ll f[nmax],g[nmax],w[nmax];

ll range(int l,int r)
{
    if (l==0) return w[r];
    return w[r]-w[l-1];
}

ll get(int x,int y)
{
    int z=log2(y-x+1);
    return min(rmq[x][z],rmq[y-(1<<z)+1][z]);
}

int rangemod(int l,int r)
{
    if (l==0) return w[r]%oo;
    return (w[r]-w[l-1])%oo;
}

ll cal(ll x,ll y)
{
    if (x>y) return 0;
    
    ll z=x+y; ll t=y-x+1;
    if (z%2==0) z/=2; else t/=2;
    z%=oo; t%=oo;
    
    return z*t%oo;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin>>n;
    for (int i=1;i<=n;++i) 
    {
        cin>>h[i];
        rmq[i][0]=h[i];
    }
    
    for (int i=1;i<=n;++i)
    {
        cin>>w[i];
        w[i]+=w[i-1];
    }
    
    for (int j=1;j<20;++j)
        for (int i=0;i<=n-(1<<j)+1;++i)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+(1<<(j-1))][j-1]);
    
    for (int i=1;i<=n;++i)
    {
        int l=0; int r=i-1;
        while (l<r)
        {
            int mid=(l+r+1)>>1;
            if (get(mid,i)<h[i]) l=mid;
            else r=mid-1;
        }
        
        f[i] = f[i] + cal(1,h[i]) * cal(range(l+1,i-1)+1,range(l+1,i)) %oo; if (f[i]>=oo) f[i]-=oo;
        f[i] = f[i] + g[l] * rangemod(i,i) %oo; if (f[i]>=oo) f[i]-=oo;
        
        g[i] = g[i] + cal(1,h[i]) * rangemod(l+1,i) %oo; if (g[i]>=oo) g[i]-=oo;
        g[i] = g[i] + g[l]; if (g[i]>=oo) g[i]-=oo;
    }
    
    int res=0;
    for (int i=1;i<=n;++i)
    {
        res+=f[i];
        if (res>=oo) res-=oo;
    }
    
    cout<<res;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 39 ms 6612 KB Output is correct
4 Correct 84 ms 12760 KB Output is correct
5 Correct 84 ms 12760 KB Output is correct
6 Correct 87 ms 12740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 7 ms 1484 KB Output is correct
3 Correct 36 ms 6580 KB Output is correct
4 Correct 92 ms 12920 KB Output is correct
5 Correct 86 ms 12792 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 7 ms 1484 KB Output is correct
4 Correct 36 ms 6552 KB Output is correct
5 Correct 90 ms 12784 KB Output is correct
6 Correct 87 ms 12752 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 7 ms 1484 KB Output is correct
9 Correct 39 ms 6532 KB Output is correct
10 Correct 86 ms 12740 KB Output is correct
11 Correct 88 ms 12800 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 39 ms 7124 KB Output is correct
12 Correct 96 ms 13972 KB Output is correct
13 Correct 97 ms 13912 KB Output is correct
14 Correct 86 ms 13996 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 7 ms 1700 KB Output is correct
17 Correct 37 ms 7492 KB Output is correct
18 Correct 87 ms 15236 KB Output is correct
19 Correct 88 ms 14796 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 9 ms 1744 KB Output is correct
22 Correct 43 ms 7588 KB Output is correct
23 Correct 89 ms 14640 KB Output is correct
24 Correct 89 ms 14660 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 464 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 7 ms 1748 KB Output is correct
31 Correct 8 ms 1740 KB Output is correct
32 Correct 40 ms 7456 KB Output is correct
33 Correct 39 ms 7524 KB Output is correct
34 Correct 87 ms 14480 KB Output is correct
35 Correct 96 ms 14552 KB Output is correct
36 Correct 97 ms 14656 KB Output is correct
37 Correct 93 ms 14752 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 89 ms 14672 KB Output is correct
40 Correct 96 ms 14660 KB Output is correct
41 Correct 97 ms 14712 KB Output is correct
42 Correct 85 ms 14788 KB Output is correct