# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
694733 | hgmhc | Fancy Fence (CEOI20_fancyfence) | C++17 | 40 ms | 5800 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; using ll = long long;
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
const int N = 100003, MOD = 1e9+7;
int n;
ll h[N], w[N], x[N], c[N], sum, ans;
stack<int> s;
ll C(ll n){return (n*(n-1)/2)%MOD;}
int main() {
scanf("%d", &n);
rep(i,1,n) scanf("%lld", &h[i]);
rep(i,1,n) scanf("%lld", &w[i]), x[i] = (x[i-1]+w[i])%MOD;
rep(i,1,n) {
while (not empty(s) and h[s.top()] > h[i]) sum = (sum-c[s.top()])%MOD, s.pop();
ans += (x[i-1]-(empty(s)?0:x[s.top()]))*C(h[i]+1)%MOD*w[i]%MOD;
ans += sum*w[i]%MOD + C(w[i]+1)*C(h[i]+1)%MOD;
ans %= MOD;
c[i] = (x[i]-(empty(s)?0:x[s.top()]))*C(h[i]+1)%MOD;
sum = (sum+c[i])%MOD;
s.push(i);
}
printf("%lld\n",(ans%MOD+MOD)%MOD);
}
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... |