Submission #944875

#TimeUsernameProblemLanguageResultExecution timeMemory
944875sleepntsheepFancy Fence (CEOI20_fancyfence)C11
0 / 100
1 ms348 KiB
#include<stdio.h> #define N 100002 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) { //printf(" Choose %lld %lld : %lld\n",ww,hh,((ww+1ll)*ww/2)*((hh+1ll)*hh/2)); return ((ww+1ll)*ww/2)*((hh+1ll)*hh/2); } void dfs(int u,long long ll,long long rr,int y,int yy) { if(!u)return; long long ww=pw[rr]-pw[ll-1]; z = z + c(ww,y) - c(ww,yy); //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(w[p[i]]>w[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 (stderr)

fancyfence.c: In function 'main':
fancyfence.c:26:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d",&n);
      |     ^~~~~~~~~~~~~~
fancyfence.c:27:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     for(int i=1;i<=n;++i)scanf("%d",h+i);
      |                          ^~~~~~~~~~~~~~~
fancyfence.c:28:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     for(int i=1;i<=n;++i)scanf("%d",w+i),pw[i]=pw[i-1]+w[i];
      |                          ^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...