제출 #915448

#제출 시각아이디문제언어결과실행 시간메모리
915448null_aweFancy Fence (CEOI20_fancyfence)C++17
0 / 100
1 ms856 KiB
// #include <bits/stdc++.h> #include <vector> #include <stack> #include <fstream> using namespace std; #define int long long #define pii pair<int, int> const int MOD = 1e9 + 7; const int INV2 = 500000004; ifstream cin("a"); ofstream cout("b"); int32_t main() { int n; cin >> n; vector<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<int> hsum, area; stack<pii> hs; hsum.push(0), area.push(0); hs.push({0, 0}); int ans = 0; for (int i = 0; i < n; ++i) { // add indiv to answer: ans += (h[i] * (h[i] + 1) / 2 % MOD) * (w[i] * (w[i] + 1) / 2 % MOD) % MOD; // cout << ans << ' '; // remove unneccesary: int nw = 0; while (hs.top().first >= h[i]) nw += hs.top().second, hsum.pop(), area.pop(), hs.pop(); // insert (h[i], nw): // cout << "nw " << nw << ' '; int lh = hs.top().first + 1; if (nw > 0) { hsum.push((hsum.top() + (h[i] + lh) % MOD * (h[i] - lh + 1) % MOD * INV2 % MOD) % MOD); area.push((area.top() + hsum.top() * nw % MOD) % MOD); hs.push({h[i], w[i]}); } // add rest to answer: ans = (ans + w[i] * area.top() % MOD) % MOD; // insert (h[i], w[i]): if (nw > 0) hsum.pop(), area.pop(), hs.pop(); lh = hs.top().first + 1; w[i] = (w[i] + nw) % MOD; // cout << lh << ' ' << h[i] << ' '; hsum.push((hsum.top() + (h[i] + lh) % MOD * (h[i] - lh + 1) % MOD * INV2 % MOD) % MOD); // cout << hsum.top() << ' '; area.push((area.top() + hsum.top() * w[i] % MOD) % MOD); hs.push({h[i], w[i]}); // cout << ans << '\n'; } cout << ans << '\n'; return 0; } /* System.out.println("Hello World"); public static double yamom(String "s"){ } */
#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...