제출 #931695

#제출 시각아이디문제언어결과실행 시간메모리
931695jcelinFancy Fence (CEOI20_fancyfence)C++14
100 / 100
22 ms13784 KiB
#include <bits/stdc++.h> //#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef long double ld; #define ii pair<int,int> #define pll pair<ll,ll> #define vi vector<int> #define vii vector<ii> #define vll vector<ll> #define vpll vector<pll> #define msi multiset<int> #define si set<int> #define PB push_back #define PF push_front #define PPB pop_back #define PPF pop_front #define X first #define Y second #define MP make_pair #define FOR(i, a, b) for (int i = int(a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) #define all(x) (x).begin(), (x).end() const int mod = 1e9 + 7; const int MOD = 998244353; const int inf = mod; const ll INF = 1e18; const int MAXN = 1e6 + 7; const int logo = 17; const int off = 1 << logo; const int trsz = off << 1; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, 1, -1}; vpll st; int ans, n, in2; ll pf[MAXN], w[MAXN], h[MAXN], dp[MAXN]; int add(ll a, ll b){ return (a + b) % mod; } int mul(ll a, ll b){ return (a * b) % mod; } int sub(ll a, ll b){ return (a - b + mod) % mod; } int exp(int b, ll e){ int ret = 1; while(e){ if(e & 1) ret = mul(ret, b); b = mul(b, b); e /= 2; } return ret; } int ch2(ll a){ return mul(in2, mul(a, a + 1)); } void solve(){ cin >> n; in2 = exp(2, mod - 2); for(int i=1; i<=n; i++) cin >> h[i]; for(int i=1; i<=n; i++) cin >> w[i], pf[i] = add(pf[i - 1], w[i]); st.PB({0, 0}); for(int i=1; i<=n; i++){ while(h[st.back().X] > h[i]) st.PPB(); ll su = add(st.back().Y, mul(ch2(h[i]), sub(pf[i - 1], pf[st.back().X]))); dp[i] = add(mul(su, w[i]), mul(ch2(h[i]), ch2(w[i]))); st.PB({i, add(su, mul(ch2(h[i]), w[i]))}); ans = add(ans, dp[i]); } cout << ans << "\n"; } int main(){ ios_base::sync_with_stdio(false); 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...