Submission #1288170

#TimeUsernameProblemLanguageResultExecution timeMemory
1288170zyntherixFancy Fence (CEOI20_fancyfence)C++20
0 / 100
1 ms584 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int, int> #define vi vector<int> #define vs vector<string> #define vb vector<bool> #define vpi vector<pi> #define pb push_back #define all(a) (a).begin(), (a).end() const int mod = 1e9 + 7; int md_inv_2 = 500000004; int sm(int x) { return (((x * (x + 1)) % mod) * md_inv_2) % mod; } void solve() { int n; cin >> n; int h[n + 1], w[n + 1]; 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; vpi v; // height, start_pos v.pb({0, 0}); int ans = 0; int pos = 1; for (int i = 0; i <= n; i++) { int curr = pos; int gwi = 0; vpi v2; while (h[i] < v.back().first) { auto x = v.back(); v.pop_back(); v2.pb({h[i], x.second}); int wi = (curr - x.second); gwi += wi; int hz = (((sm(x.first) - sm(h[i])) % mod) + mod) % mod; int vr = (((sm(gwi) - sm(gwi - wi)) % mod) + mod) % mod; ans = (ans + (hz * vr) % mod) % mod; curr = x.second; } for (auto p : v2) v.pb(p); if (h[i] > v.back().first) { v.pb({h[i], pos}); } pos += w[i]; } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#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...