Submission #946370

#TimeUsernameProblemLanguageResultExecution timeMemory
946370hmm789Fancy Fence (CEOI20_fancyfence)C++14
12 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF 1000000000000000000 #define MOD 1000000007 struct node { int s, e, m, sm, mn; node *l, *r; node(int _s, int _e) { s = _s, e = _e, m = (s+e)/2, sm = mn = 0; if(s != e) { l = new node(s, m); r = new node(m+1, e); } } void update(int x, int val) { if(s == e) {sm = mn = val; return;} else if(x > m) r->update(x, val); else l->update(x, val); sm = (l->sm + r->sm) % MOD; mn = min(l->mn, r->mn); } int rsum(int x, int y) { if(x > y) return 0; if(x <= s && e <= y) return sm; else if(x > m) return r->rsum(x, y); else if(y <= m) return l->rsum(x, y); else return (l->rsum(x, y) + r->rsum(x, y)) % MOD; } int rmin(int x, int y) { if(x > y) return -INF; if(x <= s && e <= y) return mn; else if(x > m) return r->rmin(x, y); else if(y <= m) return l->rmin(x, y); else return min(l->rmin(x, y), r->rmin(x, y)); } } *rh, *rw; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, ans = 0, sm = 0; cin >> n; int h[n], w[n]; for(int i = 0; i < n; i++) cin >> h[i]; for(int i = 0; i < n; i++) cin >> w[i]; stack<tuple<int, int, int>> s; for(int i = 0; i < n; i++) { int num = (h[i]+1)*h[i]/2 % MOD, num2 = (w[i]+1)*w[i]/2 % MOD; ans += num * num2 % MOD; ans %= MOD; int nnw = w[i], nv; while(s.size() && get<0>(s.top()) >= h[i]) { int nh, nw, val; tie(nh, nw, val) = s.top(); s.pop(); ans += w[i]*nw % MOD * num % MOD; ans %= MOD; sm -= val; nnw += nw; } ans += w[i]*sm % MOD; ans %= MOD; nv = num * nnw % MOD; sm += nv; s.push({h[i], nnw, nv}); } cout << ans; }
#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...