Submission #291192

#TimeUsernameProblemLanguageResultExecution timeMemory
291192TadijaSebezFancy Fence (CEOI20_fancyfence)C++11
100 / 100
43 ms1916 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int mod=1e9+7; int add(int x,int y){x+=y;return x>=mod?x-mod:x;} void ckadd(int&x,int y){x=add(x,y);} int sub(int x,int y){x-=y;return x<0?x+mod:x;} void cksub(int&x,int y){x=sub(x,y);} int mul(int x,int y){return (ll)x*y%mod;} int C2(int x){return (ll)x*(x+1)/2%mod;} const int N=100050; int h[N],w[N],H[N],W[N],c; int main(){ int n; scanf("%i",&n); for(int i=1;i<=n;i++)scanf("%i",&h[i]); for(int i=1;i<=n;i++)scanf("%i",&w[i]); int sum=0,ans=0; for(int i=1;i<=n;i++){ int sum_w=0; while(c>0&&H[c]>=h[i]){ ckadd(sum_w,W[c]); cksub(sum,mul(C2(H[c]),W[c])); c--; } ckadd(ans,mul(w[i],add(sum,mul(sum_w,C2(h[i]))))); ckadd(ans,mul(C2(w[i]),C2(h[i]))); ckadd(sum_w,w[i]); ckadd(sum,mul(sum_w,C2(h[i]))); c++;H[c]=h[i];W[c]=sum_w; } printf("%i\n",ans); return 0; }

Compilation message (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |  scanf("%i",&n);
      |  ~~~~~^~~~~~~~~
fancyfence.cpp:16:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  for(int i=1;i<=n;i++)scanf("%i",&h[i]);
      |                       ~~~~~^~~~~~~~~~~~
fancyfence.cpp:17:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  for(int i=1;i<=n;i++)scanf("%i",&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...