# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119381 | TrieTr | Fancy Fence (CEOI20_fancyfence) | C++14 | 2 ms | 336 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;
void local() {
#define taskname ""
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
}
#define ll long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template<class X, class Y> bool mini(X &a, const Y &b) {return (a > b) ? a = b, true : false;}
template<class X, class Y> bool maxi(X &a, const Y &b) {return (a < b) ? a = b, true : false;}
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
void add(int& x, int y) {
if((x += y) >= mod) x -= mod;
}
int n, h[N], w[N], le[N], ri[N];
ll pf[N];
int main() {
fastio; local();
cin >> n;
for(int i = 1; i <= n; i++) cin >> h[i];
for(int i = 1 ;i <= n; i++) cin >> w[i], pf[i] = pf[i - 1] + w[i];
stack<int> st;
for(int i = 1; i <= n; i++) {
while(!st.empty() && h[st.top()] > h[i]) st.pop();
le[i] = st.empty() ? 0 : st.top();
st.emplace(i);
}
st = stack<int>();
for(int i = n; i > 0; i--) {
while(!st.empty() && h[st.top()] >= h[i]) st.pop();
ri[i] = st.empty() ? n + 1 : st.top();
st.emplace(i);
}
int inv2 = 5e8 + 4;
int res = 0;
for(int i = 1; i <= n; i++) {
ll len = pf[ri[i] - 1] - pf[le[i]];
int cur = 1ll * len * (len + 1) % mod * inv2 % mod * h[i] % mod;
add(res, cur);
}
cout << res;
}
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... |