Submission #1119430

#TimeUsernameProblemLanguageResultExecution timeMemory
1119430TrieTrFancy Fence (CEOI20_fancyfence)C++14
43 / 100
21 ms4088 KiB
#include<bits/stdc++.h> using namespace std; void local() { #define taskname "" if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } } #define ll long long #define fi first #define se second #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); template<class X, class Y> bool mini(X &a, const Y &b) {return (a > b) ? a = b, true : false;} template<class X, class Y> bool maxi(X &a, const Y &b) {return (a < b) ? a = b, true : false;} const int N = 1e6 + 5; const int mod = 1e9 + 7; void add(int& x, int y) { if((x += y) >= mod) x -= mod; } int n, h[N], w[N], dp[N], ri[N]; ll pf[N]; int inv2 = 5e8 + 4; int cal(int x) { return 1ll * x * (x + 1) % mod * inv2 % mod; } int main() { fastio; local(); cin >> n; for(int i = 1; i <= n; i++) cin >> h[i]; for(int i = 1 ;i <= n; i++) cin >> w[i], pf[i] = pf[i - 1] + w[i]; stack<int> st; for(int i = n; i > 0; i--) { while(!st.empty() && h[st.top()] >= h[i]) st.pop(); ri[i] = st.empty() ? n + 1 : st.top(); st.emplace(i); } int res = 0; for(int i = n; i > 0; i--) { add(res, 1ll * cal(w[i]) * cal(h[i]) % mod); add(res, 1ll * (pf[ri[i] - 1] - pf[i]) % mod * w[i] % mod * cal(h[i]) % mod); add(res, 1ll * dp[ri[i]] * w[i] % mod); add(dp[i], dp[ri[i]]); add(dp[i], 1ll * (pf[ri[i] - 1] - pf[i - 1]) % mod * h[i] % mod); } cout << res; }

Compilation message (stderr)

fancyfence.cpp: In function 'void local()':
fancyfence.cpp:7:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...