Submission #930351

#TimeUsernameProblemLanguageResultExecution timeMemory
930351haxormanFancy Fence (CEOI20_fancyfence)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int mxN = 1e5 + 7; const int MOD = 1e9 + 7; int pref[mxN], nex[mxN], add[mxN]; pair<int,int> arr[mxN]; int nc2(int n) { return n * (n - 1) / 2; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> arr[i].first; } for (int i = 1; i <= n; ++i) { cin >> arr[i].second; pref[i] = pref[i - 1] + arr[i].second; } vector<int> st = {n + 1}; for (int i = n; i >= 1; --i) { while (st.size() && arr[i].first <= arr[st.back()].first) { st.pop_back(); } assert(st.size()); nex[i] = st.back(); st.push_back(i); } int ans = 0, sub = 0; for (int i = 1; i <= n; ++i) { sub -= add[i]; int w = pref[nex[i] - 1] - pref[i - 1]; ans += (nc2(arr[i].first + 1) - sub) % MOD * nc2(w + 1) % MOD; ans %= MOD; add[nex[i]] += (nc2(arr[i].first + 1) - sub); sub = nc2(arr[i].first + 1); } 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...