Submission #923960

#TimeUsernameProblemLanguageResultExecution timeMemory
923960treap_enjoyerFancy Fence (CEOI20_fancyfence)C++14
0 / 100
1 ms556 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("Ofast,unroll-loops") #define ll long long #define all(x) x.begin(), x.end() #define ld long double #define pii pair<int, int> #define int long long using namespace std; using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int INF = 1e9 + 7; const int MAXN = 1e5 + 5; ll bin_pow(int a, int b){ if(!b) return 1; if(b & 1) return (a * bin_pow(a, b - 1)) % INF; else return bin_pow((a * a) % INF, b / 2); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // ifstream cin("input.txt"); // ofstream cout("output.txt"); int n; cin >> n; vector<int> h(n + 1); vector<int> w(n + 1); bool flg = 1; for(int i = 1; i <= n; i++){ cin >> h[i]; if(i != 1 && h[i] != h[i - 1]) flg = 0; } for(int i = 1; i <= n; i++){ cin >> w[i]; } vector<ll> dp(n + 1, 0); stack<pair<int, int> > st; st.push({0, 0}); vector<ll> pref(n + 1); for(int i = 1; i <= n; i++){ pref[i] += pref[i - 1]; pref[i] += w[i]; pref[i] %= INF; } vector<int> ans(n + 1, 0); for(int i = 1; i <= n; i++){ while(st.top().first >= h[i]){ st.pop(); } ll sumw = pref[i] - pref[st.top().second]; ll x = 0; x = h[i]; x *= h[i] + 1; x %= INF; x *= bin_pow(2, INF - 2); x %= INF; x *= sumw; x %= INF; dp[i] += dp[st.top().second]; dp[i] %= INF; dp[i] += x; dp[i] %= INF; ans[i] += ans[i - 1]; ans[i] += dp[i]; ans[i] += dp[st.top().second] * (w[i] - 1); ans[i] %= INF; x = 1; x *= h[i]; x %= INF; x *= h[i] + 1; x %= INF; x *= bin_pow(2, INF - 2); x %= INF; x *= sumw - w[i]; x *= w[i] - 1; x %= INF; ans[i] += x; ans[i] %= INF; x = 1; x *= h[i] + 1; x %= INF; x *= h[i]; x %= INF; x *= bin_pow(2, INF - 2); x %= INF; x *= w[i] - 1; x %= INF; x *= w[i]; x %= INF; x *= bin_pow(2, INF - 2); x %= INF; ans[i] += x; ans[i] %= INF; st.push({h[i], i}); } // cout << "goida" << endl; for(int i = 1; i <= n; i++){ cout << dp[i] << " "; } cout << ans[n] << endl; }

Compilation message (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:33:10: warning: variable 'flg' set but not used [-Wunused-but-set-variable]
   33 |     bool flg = 1;
      |          ^~~
#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...