Submission #944904

# Submission time Handle Problem Language Result Execution time Memory
944904 2024-03-13T07:47:28 Z sleepntsheep Fancy Fence (CEOI20_fancyfence) C
25 / 100
21 ms 10072 KB
#include<stdio.h>

#define int long long
#define N 100002
#define M 1000000007ll
int n,h[N],w[N],p[N],l[N],r[N];
long long pw[N],z;

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

void dfs(int u,int ll,int rr,int yy)
{
    int y=h[u];
    if(!u||ll>rr)return;
    long long ww=(pw[rr]-pw[ll-1]);
    z = (z + (c(ww,y) + M - c(ww,yy)) % M) % M;
    //printf(" AT %d : [%lld %lld], %d %lld\n",u,pw[ll-1]+1,pw[rr],y,z);
    dfs(l[u],ll,u-1,y);
    dfs(r[u],u+1,rr,y);
}

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)
    {
        p[i]=i-1;
        while(h[p[i]]>=h[i])p[i]=p[p[i]];
        l[i]=r[p[i]];
        r[p[i]]=i;
        p[l[i]]=i;
    }

    for(int i=1;i<=n;++i)if(!p[i])dfs(i,1,n,0);
    printf("%lld",z);
}

Compilation message

fancyfence.c: In function 'main':
fancyfence.c:29:13: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'long long int *' [-Wformat=]
   29 |     scanf("%d",&n);
      |            ~^  ~~
      |             |  |
      |             |  long long int *
      |             int *
      |            %lld
fancyfence.c:30:34: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'long long int *' [-Wformat=]
   30 |     for(int i=1;i<=n;++i)scanf("%d",h+i);
      |                                 ~^  ~~~
      |                                  |   |
      |                                  |   long long int *
      |                                  int *
      |                                 %lld
fancyfence.c:31:34: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'long long int *' [-Wformat=]
   31 |     for(int i=1;i<=n;++i)scanf("%d",w+i),pw[i]=pw[i-1]+w[i];
      |                                 ~^  ~~~
      |                                  |   |
      |                                  |   long long int *
      |                                  int *
      |                                 %lld
fancyfence.c:29:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d",&n);
      |     ^~~~~~~~~~~~~~
fancyfence.c:30:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     for(int i=1;i<=n;++i)scanf("%d",h+i);
      |                          ^~~~~~~~~~~~~~~
fancyfence.c:31:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     for(int i=1;i<=n;++i)scanf("%d",w+i),pw[i]=pw[i-1]+w[i];
      |                          ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 9 ms 5208 KB Output is correct
4 Correct 21 ms 10072 KB Output is correct
5 Correct 20 ms 7516 KB Output is correct
6 Correct 21 ms 5464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -