# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
572517 | teki | Fancy Fence (CEOI20_fancyfence) | C++11 | 43 ms | 7536 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>
typedef long long ll;
#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
#define MN 1000000007
using namespace std;
ll n, curr = 0, res = 0, x = 0;
ll h[100001],w[100001];
ll calcZbir(ll w) {
w %= MN;
return (w*(w-1)/2)%MN;
}
int main()
{
#if LOCAL_DEBUG
fstream cin("in.txt");
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for (int i = 0; i<n; i++) cin>>h[i];
for (int i = 0; i<n; i++) cin>>w[i];
n++;
stack<pair<ll,ll>> st;
st.push({0,-1});
for (int i = 0; i<n; i++) {
vector<pair<ll,ll>> v2;
while(st.top().second >= h[i]) {
v2.pb(st.top());
st.pop();
v2.back().first -= st.top().first;
}
for (int j = 1; j<v2.size(); j++) v2[j].first += v2[j-1].first;
v2.pb({MN+1,h[i]});
for (int j = 0; j<v2.size()-1; j++) {
ll temp = v2[j].second-v2[j+1].second;
res += (calcZbir(v2[j].first+1))*(temp*v2[j+1].second%MN+calcZbir(temp+1));
res %= MN;
}
x += w[i];
st.push({x,h[i]});
}
cout<<res<<endl;
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... |