Submission #414599

#TimeUsernameProblemLanguageResultExecution timeMemory
414599arnevesFancy Fence (CEOI20_fancyfence)C++17
12 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define f first #define s second #define all(x) x.begin(), x.end() const int MOD = 1'000'000'007; const int MX = 400'005; //long double PI = 3.14159265358979323846264338327950; int main(){ cin.tie(0);ios_base::sync_with_stdio(0); //freopen ("out.txt","w",stdout); //int n_casos=1; cin>>n_casos; //while(n_casos--) caso_teste(); int n; cin>>n; ll h[n+1], w[n+1]; stack<pair<ll,ll>> s; s.push(make_pair(0,0));//par (altura,largura) ll ans=0; for(int i=0; i<n; i++){ cin>>h[i]; } for(int i=0; i<n; i++){ cin>>w[i]; } h[n]=0; w[n]=0; for(int i=0; i<n+1; i++){ ll largura; while((s.top()).f>h[i]){ largura=s.top().s; ll altura=s.top().f; ll ALTURA=s.top().f; s.pop(); altura=max(h[i],s.top().f); ans+=( (((ALTURA*(ALTURA+1ll))/2ll)%MOD) * (((largura*(largura+1ll))/2ll)%MOD) )%MOD; ans-=( (((altura*(altura+1ll))/2ll)%MOD) * (((largura*(largura+1ll))/2ll)%MOD) )%MOD; //cout<<ALTURA<<' '<<altura<<' '<<ans<<'\n'; if(s.top().f>=h[i])s.top().s+=largura; else w[i]+=largura; } if(h[i]==s.top().f){ s.top().s+=w[i]; }else{ s.push({h[i],w[i]}); } } cout<<ans<<'\n';; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...