#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MODD = 1e9+7;
const int INV = 5e8+4;
int mult(int n){
int temp = 1;
temp *= (n);
temp %= MODD;
temp *= (n+1);
temp %= MODD;
temp *= INV;
temp %= MODD;
return temp;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int h[n];
int w[n];
bool same = true;
bool less = true;
for(int i=0; i<n; i++){
cin >> h[i];
if(i>0 && h[i]!=h[i-1]){
same = false;
}
if(i>0 && h[i]<h[i-1]){
less = false;
}
}
for(int i=0; i<n; i++){
cin >> w[i];
}
if(n<=1000){
int ans = 0;
for(int i=0; i<n; i++){
int temp = mult(w[i]);
temp %= MODD;
temp *= mult(h[i]);
temp %= MODD;
ans += temp;
ans %= MODD;
}
for(int i=0; i<n; i++){
int minn = h[i];
for(int j=i+1; j<n; j++){
minn = min(minn, h[j]);
int temp = w[i]*w[j];
temp %= MODD;
temp *= mult(minn);
temp %= MODD;
ans += temp;
ans %= MODD;
}
}
cout << ans << '\n';
}
else if(same){
int summ = 0;
for(int i=0; i<n; i++){
summ += w[i];
summ %= MODD;
}
int ans = mult(h[0]);
ans *= mult(summ);
ans %= MODD;
cout << ans << '\n';
}
else if(less){
int ans = 0;
for(int i=0; i<n; i++){
int temp = mult(w[i]);
temp %= MODD;
temp *= mult(h[i]);
temp %= MODD;
ans += temp;
ans %= MODD;
}
int summ = 0;
for(int i=0; i<n; i++){
summ += w[i];
summ %= MODD;
}
for(int i=0; i<n; i++){
summ -= w[i];
summ += MODD;
summ %= MODD;
int temp = w[i]*summ;
temp %= MODD;
temp *= mult(h[i]);
temp %= MODD;
ans += temp;
ans %= MODD;
}
cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Incorrect |
9 ms |
1116 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
608 KB |
Output is correct |
3 |
Correct |
8 ms |
1228 KB |
Output is correct |
4 |
Correct |
15 ms |
1884 KB |
Output is correct |
5 |
Correct |
17 ms |
1884 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
8 ms |
1116 KB |
Output is correct |
5 |
Correct |
16 ms |
1884 KB |
Output is correct |
6 |
Correct |
16 ms |
1884 KB |
Output is correct |
7 |
Correct |
5 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
10 ms |
1236 KB |
Output is correct |
10 |
Correct |
18 ms |
1880 KB |
Output is correct |
11 |
Correct |
17 ms |
1880 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
5 ms |
464 KB |
Output is correct |
9 |
Correct |
6 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
464 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
5 ms |
464 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
348 KB |
Output is correct |
11 |
Incorrect |
6 ms |
1116 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |