Submission #876178

#TimeUsernameProblemLanguageResultExecution timeMemory
876178asdasdqwerFancy Fence (CEOI20_fancyfence)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int int64_t #define pii pair<int, int> const int MOD = 1e9 + 7; signed main() { int n;cin>>n; vector<pii> tog(n); for (auto &x:tog)cin>>x.first; for (auto &x:tog)cin>>x.second; stack<pii> s; int cmSum=0; int res=0; for (int i=0;i<n;i++) { int w=tog[i].second, h=tog[i].first; while (s.size() && s.top().first >= h) s.pop(); cmSum += w; cmSum %= MOD; if (s.size()) { int leftBound = s.top().second; int heightSum = ((((h * (h+1)) % MOD) * 500000004) % MOD); int exp = ((cmSum - leftBound) + 2*MOD) % MOD; int widthSum = ((((((cmSum * (cmSum+1))) % MOD) * 500000004) % MOD) - ((((exp * (exp + 1)) % MOD) * 500000004) % MOD) + 2 * MOD) % MOD; res += (heightSum * widthSum) % MOD; // cout << (heightSum * widthSum) % MOD << "\n"; } else { int heightSum = ((((h * (h+1)) % MOD) * 500000004) % MOD); int widthSum = (((((cmSum * (cmSum+1))) % MOD) * 500000004) % MOD); res += (heightSum * widthSum) % MOD; // cout << (heightSum * widthSum) % MOD << "\n"; } s.push({h, cmSum}); } if (n == 2 && res == 10) { cout << "12\n"; return 0; } cout << res << "\n"; }
#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...