답안 #944935

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

#define int long long
#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("%lld",&n);
    for(int i=1;i<=n;++i)scanf("%lld",h+i);
    for(int i=1;i<=n;++i)scanf("%lld",w+i),pw[i]=pw[i-1]+w[i];

    //for(int i=1;i<=n;++i)printf(" %d %d %d\n",i,l[i],r[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:33:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%lld",&n);
      |     ^~~~~~~~~~~~~~~~
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("%lld",h+i);
      |                          ^~~~~~~~~~~~~~~~~
fancyfence.c:35:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     for(int i=1;i<=n;++i)scanf("%lld",w+i),pw[i]=pw[i-1]+w[i];
      |                          ^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 9 ms 3676 KB Output is correct
4 Correct 21 ms 5100 KB Output is correct
5 Correct 22 ms 4444 KB Output is correct
6 Correct 17 ms 4176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 2 ms 2908 KB Output is correct
3 Correct 10 ms 4488 KB Output is correct
4 Correct 20 ms 6224 KB Output is correct
5 Correct 20 ms 6236 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 10 ms 4700 KB Output is correct
5 Correct 20 ms 7004 KB Output is correct
6 Correct 21 ms 7116 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 3 ms 2740 KB Output is correct
9 Correct 13 ms 4956 KB Output is correct
10 Correct 19 ms 6732 KB Output is correct
11 Correct 20 ms 6996 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 9 ms 4108 KB Output is correct
12 Correct 19 ms 6224 KB Output is correct
13 Correct 18 ms 5724 KB Output is correct
14 Correct 17 ms 5720 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 3 ms 2908 KB Output is correct
17 Correct 10 ms 4828 KB Output is correct
18 Correct 20 ms 6832 KB Output is correct
19 Correct 20 ms 7000 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2908 KB Output is correct
22 Correct 10 ms 4960 KB Output is correct
23 Correct 19 ms 6736 KB Output is correct
24 Correct 20 ms 6764 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2488 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 10 ms 4440 KB Output is correct
33 Correct 11 ms 4396 KB Output is correct
34 Correct 20 ms 6028 KB Output is correct
35 Correct 20 ms 6040 KB Output is correct
36 Correct 24 ms 6220 KB Output is correct
37 Correct 21 ms 6228 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 27 ms 6228 KB Output is correct
40 Correct 20 ms 6212 KB Output is correct
41 Correct 20 ms 6988 KB Output is correct
42 Correct 21 ms 9564 KB Output is correct