Submission #944891

# Submission time Handle Problem Language Result Execution time Memory
944891 2024-03-13T07:32:07 Z sleepntsheep Fancy Fence (CEOI20_fancyfence) C
12 / 100
1 ms 500 KB
#include<stdio.h>

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

long long c(long long ww,long long hh)
{
    long long wc2=((ww+1)%M*ww%M)%M*500000004ll%M;
    long long hc2=((hh+1)%M*hh%M)%M*500000004ll%M;
    return wc2*hc2%M;
}

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

int 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,h[i],0);
    printf("%lld",z);
}

Compilation message

fancyfence.c: In function 'main':
fancyfence.c:28:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d",&n);
      |     ^~~~~~~~~~~~~~
fancyfence.c:29:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     for(int i=1;i<=n;++i)scanf("%d",h+i);
      |                          ^~~~~~~~~~~~~~~
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",w+i),pw[i]=pw[i-1]+w[i];
      |                          ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 500 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -