Submission #999418

#TimeUsernameProblemLanguageResultExecution timeMemory
999418ErJFancy Fence (CEOI20_fancyfence)C++17
100 / 100
23 ms4216 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<ll> #define vp vector<pp> #define vvi vector<vi> #define vvp vector<vp> #define pp pair<ll, ll> #define inf 1000000000000000 #define rep(i,n) for(ll i = 0; i < n; i++) #define mod 1000000007 ll get(ll h, ll w){ h %= mod; w %= mod; return (((h * (h + 1)/ 2) % mod) * ((w * (w + 1) / 2) % mod) % mod); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; vi H(n + 1), W(n + 1); rep(i,n){ cin >> H[i]; } H[n] = 0; W[n] = 0; rep(i,n) cin >> W[i]; vector<pp> q; q.push_back({-1, -1}); ll ans = 0; rep(i,n + 1){ ll akt = 0; while(q.back().first >= H[i]){ pp seclast = q[q.size() - 2]; if(seclast.first >= H[i]){ ans += get(q.back().first, q.back().second); ans -= get(seclast.first, q.back().second); ans %= mod; if(ans < 0) ans += mod; ll www = q.back().second; q.pop_back(); q.back().second += www; }else{ ans += get(q.back().first, q.back().second); ans -= get(H[i], q.back().second); ans %= mod; if(ans < 0) ans += mod; akt = q.back().second; q.pop_back(); } ans %= mod; } q.push_back({H[i], W[i] + akt}); } cout << ans << endl; }
#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...