답안 #944937

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944937 2024-03-13T08:25:48 Z sleepntsheep Fancy Fence (CEOI20_fancyfence) C
100 / 100
23 ms 6348 KB
#include<stdio.h>

#define N 100002
#define M 1000000007ll

int n,h[N],w[N],l[N],r[N];
long long pw[N],z;

long long c2(long long x){return (x-1)*x%M*500000004ll%M;}

long long c(long long ww,long long hh)
{
    ww%=M;
    hh%=M;
    return c2(ww+1)*c2(hh+1)%M;
}

void dfs(int u,int ll,int rr,int yy)
{
    if(!u||ll>rr)return;
    int y=h[u];
    long long ww=(pw[rr]-pw[ll-1])%M;
    z = (z + (c(ww,y) + M - c(ww,yy)) % M) % M;
    dfs(l[u],ll,u-1,y);
    dfs(r[u],u+1,rr,y);
}

int stk[N], top;

signed main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",h+i);
    for(int i=1;i<=n;++i)scanf("%d",w+i),pw[i]=pw[i-1]+w[i];

    for(int i=1;i<=n;++i)
    {
        int k=top;
        while(k&&h[stk[k]]>h[i])--k;
        if(k)r[stk[k]]=i;
        if(k<top)l[i]=stk[k+1];
        stk[++k]=i;
        top=k;
    }

    dfs(stk[1],1,n,0);
    printf("%lld",z);
}

Compilation message

fancyfence.c: In function 'main':
fancyfence.c:32:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d",&n);
      |     ^~~~~~~~~~~~~~
fancyfence.c:33:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     for(int i=1;i<=n;++i)scanf("%d",h+i);
      |                          ^~~~~~~~~~~~~~~
fancyfence.c:34:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     for(int i=1;i<=n;++i)scanf("%d",w+i),pw[i]=pw[i-1]+w[i];
      |                          ^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 9 ms 1864 KB Output is correct
4 Correct 17 ms 2908 KB Output is correct
5 Correct 18 ms 2904 KB Output is correct
6 Correct 17 ms 2656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 10 ms 1504 KB Output is correct
4 Correct 19 ms 2708 KB Output is correct
5 Correct 20 ms 2652 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 10 ms 1372 KB Output is correct
5 Correct 19 ms 2672 KB Output is correct
6 Correct 20 ms 2652 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 10 ms 1372 KB Output is correct
10 Correct 19 ms 2520 KB Output is correct
11 Correct 19 ms 2544 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 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 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 9 ms 1628 KB Output is correct
12 Correct 17 ms 2936 KB Output is correct
13 Correct 23 ms 2904 KB Output is correct
14 Correct 17 ms 2652 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 10 ms 1428 KB Output is correct
18 Correct 19 ms 2652 KB Output is correct
19 Correct 19 ms 2652 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 17 ms 1484 KB Output is correct
23 Correct 19 ms 2648 KB Output is correct
24 Correct 19 ms 2648 KB Output is correct
25 Correct 0 ms 344 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 0 ms 348 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 676 KB Output is correct
32 Correct 10 ms 1372 KB Output is correct
33 Correct 10 ms 1372 KB Output is correct
34 Correct 20 ms 2664 KB Output is correct
35 Correct 20 ms 2728 KB Output is correct
36 Correct 21 ms 2652 KB Output is correct
37 Correct 21 ms 2652 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 19 ms 2604 KB Output is correct
40 Correct 19 ms 2888 KB Output is correct
41 Correct 20 ms 3164 KB Output is correct
42 Correct 21 ms 6348 KB Output is correct