Submission #1292023

#TimeUsernameProblemLanguageResultExecution timeMemory
1292023NValchanovFancy Fence (CEOI20_fancyfence)C++20
100 / 100
19 ms4180 KiB
#include <iostream> #include <vector> using namespace std; typedef long long llong; const llong MOD = 1e9 + 7; const int MAXN = 1e5 + 10; const int INF = 1e9 + 10; int n; llong w[MAXN]; llong h[MAXN]; void read() { cin >> n; for(int i = 1; i <= n; i++) { cin >> h[i]; } for(int i = 1; i <= n; i++) { cin >> w[i]; } } llong comb(llong x) { x %= MOD; if(x % 2 == 0) { llong x2 = x / 2; return x2 * (x - 1LL) % MOD; } llong x2 = (x - 1) / 2; return x * x2 % MOD; } void solve() { vector < pair < llong, llong > > st; st.push_back({0, 0}); llong ans = 0; for(int i = 1; i <= n + 1; i++) { llong sumw = 0; while(st.back().first > h[i]) { sumw = (sumw + st.back().second) % MOD; llong hp = max(h[i], st[st.size() - 2].first); llong deltah = (st.back().first - hp + MOD) % MOD; ans += comb(sumw + 1) * ((comb(deltah + 1) + hp * deltah % MOD) % MOD) % MOD; ans %= MOD; st.pop_back(); } sumw = (sumw + w[i]) % MOD; if(st.back().first == h[i]) { st.back().second = (st.back().second + sumw) % MOD; } else { st.push_back({h[i], sumw}); } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); read(); 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...