Submission #863433

#TimeUsernameProblemLanguageResultExecution timeMemory
863433honanhphongFancy Fence (CEOI20_fancyfence)C++14
100 / 100
74 ms10860 KiB
#include<bits/stdc++.h> using namespace std; using lli = long long; const int mod = 1e9 + 7; const int maxn = 1e6; const int inv = 500000004; lli h[maxn], w[maxn]; int main() { lli n; cin >> n; for (lli i = 1; i <= n; i ++) { cin >> h[i]; } for (lli i = 1; i <= n; i ++) { cin >> w[i]; } n ++; vector<pair<lli,lli>> v; v.push_back({0, 0}); lli ans = 0; for(int i = 1; i <= n; i ++) { lli p = 0; while(v.back().first > h[i]) { lli m = max(h[i], v[(int)v.size() - 2].first); lli q = v.back().first - m; p = (p + v.back().second) % mod; v.pop_back(); ans += (q * (q + 1) % mod * inv % mod + q * m % mod)*(p *(p + 1) % mod * inv % mod) % mod; ans %= mod; } if(v.back().first == h[i]) { v.back().second =(v.back().second + p + w[i]) % mod; }else { v.push_back({h[i], (p + w[i]) % mod}); } } cout << ans % mod; }
#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...