Submission #863339

#TimeUsernameProblemLanguageResultExecution timeMemory
863339honanhphongFancy Fence (CEOI20_fancyfence)C++14
0 / 100
3 ms6644 KiB
#include<bits/stdc++.h> using namespace std; using lli = long long; const int mod = 1e9 + 7; const int maxn = 1e6; lli s[maxn], h[maxn], w[maxn], b[maxn], c[maxn]; vector <lli> v; 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]; } for (lli i = 1; i <= n; i ++) { s[i] = s[i - 1] + w[i]; } lli k = 0; for (lli i = 1; i <= n; i ++) { while (!v.empty() && h[v.back()] > h[i]) { v.pop_back(); } if (v.empty()) { k ++; b[k] = 0; } else { k ++; b[k] = s[v.back()]; } v.push_back(i); } while (!v.empty()) { v.pop_back(); } k = 0; for (lli i = n; i >= 1; i --) { while (!v.empty() && h[v.back()] >= h[i]) { v.pop_back(); } if (v.empty()) { k ++; c[k] = s[n] + 1; } else { k ++; c[k] = s[v.back()]; } v.push_back(i); } lli res = 0, j = n; for (lli i = 1; i <= n; i ++) { lli p = (h[i] + 1) * h[i] / 2; lli q = (w[i] + 1) * w[i] / 2; lli r = c[j] - b[i] - w[i]; res += (p * q * r); res %= mod; cout << res << " " << c[j] << " " << b[i] << " " << r << endl; j --; } cout << res % 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...