#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define pii pair<int, int>
const int MOD = 1e9 + 7;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<pii> tog(n);
for (auto &x:tog)cin>>x.first;
for (auto &x:tog)cin>>x.second;
set<int> vals;
for (auto x:tog) {
vals.insert(x.first);
}
if (vals.size() == 1) {
int sm=0;
for (auto x:tog) {
sm += x.second;
}
sm %= MOD;
int h = *vals.begin();
int heightSum = ((((h * (h+1)) % MOD) * 500000004) % MOD);
int widthSum = (((((sm * (sm+1))) % MOD) * 500000004) % MOD);
int res = (heightSum * widthSum) % MOD;
cout << res << "\n";
}
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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
360 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |