# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
320419 | tasfiq4 | Fancy Fence (CEOI20_fancyfence) | C++14 | 34 ms | 7148 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;
typedef long long int lld;
typedef pair<lld,lld > pii;
#define pi acos(-1)
#define fr(i,m,n) for(i=m;i<n;i++)
#define fu(i,m,n) for(i=m;i>=n;i--)
#define vec vector<lld>
#define pb push_back
#define pp pop_back()
#define ft first
#define sd second
#define all(v) v.begin(),v.end()
#define mom(ara) memset(ara,0,sizeof(ara));
#define m1m(ara) memset(ara,-1,sizeof(ara));
#define endl "\n"
#define eps 1.19209e-07
const lld mod=1e9+7;
lld pref[100010],suf[100010];
lld cal(lld x,lld y)
{
x%=mod;y%=mod;
lld i=(x*(x+1))/2,j=(y*(y+1))/2;
i%=mod;j%=mod;
return (i*j)%mod;
}
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
lld i,j,k,a,b,c,x,y,z,n,m,ans,t;
cin>>n;
vec h,w;
fr(i,0,n)
{
cin>>x;
h.pb(x);
}
fr(i,0,n)
{
cin>>x;
w.pb(x);
}
stack<pii> st;
fr(i,0,n)
{
if(st.empty() || st.top().ft<h[i])
{
st.push({h[i],w[i]});
pref[i]=0;
}
else
{
x=0;
while(!st.empty() && st.top().ft>=h[i])
{
x+=st.top().sd;
st.pop();
}
pref[i]=x;
st.push({h[i],x+w[i]});
}
}
while(!st.empty()) st.pop();
fu(i,n-1,0)
{
if(st.empty() || st.top().ft<=h[i])
{
st.push({h[i],w[i]});
suf[i]=0;
}
else
{
x=0;
while(!st.empty() && st.top().ft>h[i])
{
x+=st.top().sd;
st.pop();
}
suf[i]=x;
st.push({h[i],x+w[i]});
}
}
ans=0;
fr(i,0,n)
{
ans+=cal(h[i],pref[i]+w[i]+suf[i]);
ans%=mod;
ans-=(cal(pref[i],h[i])+cal(suf[i],h[i]))%mod;
ans+=mod;
ans%=mod;
}
cout<<ans<<endl;
}
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... |