#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
#define fi first
#define se second
int main(){
ll n;
cin>>n;
vector<ll> a(n),b(n);
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
ll ans=0;
for(int i=0;i<n;i++) (ans+=((b[i]*(b[i]+1))/2%mod)*((a[i]*(a[i]+1)/2)%mod))%=mod;
ans%=mod;
vector<pair<ll,ll>> s;
ll sum=0;
//高さ、幅
for(int i=0;i<n;i++){
if(i==0){
s.push_back({a[i],b[i]});
sum+=(a[i]*(a[i]+1)/2)%mod*b[i];
sum%=mod;
continue;
}
ll sum2=b[i];
while(s.size()&&s.back().fi>a[i]){
sum2+=s.back().se;
sum-=(s.back().fi*(s.back().fi+1)/2%mod)*b[i];
sum%=mod;
sum+=mod;
sum%=mod;
}
ans+=sum*b[i];
ans%=mod;
s.push_back({a[i],sum2%mod});
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1070 ms |
212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1045 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1059 ms |
212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1090 ms |
212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1070 ms |
212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |