Submission #945709

#TimeUsernameProblemLanguageResultExecution timeMemory
945709hmm789Fancy Fence (CEOI20_fancyfence)C++14
12 / 100
197 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF 1000000000000000000 #define MOD 1000000007 struct node { int s, e, m, mx, sm, lz; node *l, *r; node(int _s, int _e) { s = _s, e = _e, m = (s+e)/2, mx = sm = 0, lz = -1; l = nullptr; r = nullptr; } void prop() { if(lz == -1) return; sm = lz*(e-s+1) % MOD; mx = lz; if(s != e) { if(l == nullptr) l = new node(s, m); if(r == nullptr) r = new node(m+1, e); l->lz = lz; r->lz = lz; } lz = -1; } void rset(int x, int y, int val) { if(x > y) return; prop(); if(x <= s && e <= y) {lz = val; return;} else if(x > m) { if(r == nullptr) r = new node(m+1, e); r->rset(x, y, val); } else if(y <= m) { if(l == nullptr) l = new node(s, m); l->rset(x, y, val); } else { if(l == nullptr) l = new node(s, m); if(r == nullptr) r = new node(m+1, e); l->rset(x, y, val), r->rset(x, y, val); } if(l != nullptr) l->prop(); if(r != nullptr) r->prop(); if(l == nullptr) sm = r->sm, mx = r->mx; else if(r == nullptr) sm = l->sm, mx = l->mx; else sm = (l->sm + r->sm)%MOD, mx = min(l->mx, r->mx); } int rsum(int x, int y) { if(x > y) return 0; prop(); if(x <= s && e <= y) return sm; else if(x > m) return r==nullptr?0:r->rsum(x, y); else if(y <= m) return l==nullptr?0:l->rsum(x, y); else return ((l==nullptr?0:l->rsum(x, y)) + (r==nullptr?0:r->rsum(x, y))) % MOD; } int rmax(int x, int y) { if(x > y) return -INF; prop(); if(x <= s && e <= y) return mx; else if(x > m) return r==nullptr?-INF:r->rmax(x, y); else if(y <= m) return l==nullptr?-INF:l->rmax(x, y); else return min((l==nullptr?-INF:l->rmax(x, y)), (r==nullptr?-INF:r->rmax(x, y))); } } *root; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int h[n], w[n], dp[n]; for(int i = 0; i < n; i++) cin >> h[i]; for(int i = 0; i < n; i++) cin >> w[i]; root = new node(0, INF); int cur = 0; for(int i = 0; i < n; i++) { int l = 0, r = cur, m; while(l < r) { m = (l+r)/2; if(root->rmax(m, cur-1) <= (h[i]+1)*h[i]/2) l = m+1; else r = m; } root->rset(l, cur-1, (h[i]+1)*h[i]/2 % MOD); //cout << "a " << i << " " << l << " " << cur << endl; //for(int j = 0; j < cur; j++) cout << root->rsum(j, j) << " "; //cout << endl; int num = (w[i]+1)*w[i]/2 % MOD, num2 = (h[i]+1)*h[i]/2 % MOD; dp[i] = num * num2 % MOD + (i==0?0:dp[i-1]) + w[i]*root->rsum(0, cur-1); dp[i] %= MOD; cur += w[i]; root->rset(cur-w[i], cur-1, (h[i]+1)*h[i]/2 % MOD); //cout << i << " " << dp[i] << endl; } cout << dp[n-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...