# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
291192 | TadijaSebez | Fancy Fence (CEOI20_fancyfence) | C++11 | 43 ms | 1916 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |