#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
void solve() {
int n;
cin >> n;
pair<int,int> nums[n];
int mx = 0;
bool b = 1, b2 = 1;
for (int i = 0;i < n;i++) {
cin >> nums[i].first;
mx = max(mx, nums[i].first);
}
for (int i = 1;i < n;i++) {
if (nums[i].first != nums[i-1].first) {
b = false;
}
if (nums[i].first < nums[i-1].first) {
b2 = false;
}
}
for (int i = 0;i < n;i++) {
cin >> nums[i].second;
}
int ans = 0;
if (b) {
int len = 0;
for (int i = 0;i < n;i++) {
len += nums[i].second;
}
len%= MOD;
ans = (((mx)*(mx+1)/2)%MOD)*(((len)*(len+1)/2)%MOD);
ans %= MOD;
cout << ans;
return;
}
if (b2) {
int suf[n];
suf[n-1] = nums[n-1].second;
for (int i = n-2;i >= 0;i--) {
suf[i] = (suf[i+1] + nums[i].second)%MOD;
}
int last = 0;
int ans = 0;
for (int i = 0;i < n;i++) {
int x = ( (((nums[i].first+1)* (nums[i].first)/2)%MOD) - (((last+1)* (last)/2)%MOD) + MOD )%MOD;
int y = (((suf[i]+1)*(suf[i])/2)%MOD);
ans = (ans + (x*y))%MOD;
last = nums[i].first;
}
cout << ans;
return;
}
for (int h = 1;h <= mx;h++) {
int len = 0;
for (int i = 0;i < n;i++) {
if (nums[i].first < h) {
len %= MOD;
ans = (ans + (h * (((len)*(len+1)/2)%MOD)))%MOD;
len = 0;
} else {
len += nums[i].second;
}
}
len %= MOD;
ans = (ans + ((h) * (((len)*(len+1)/2)%MOD)))%MOD;
len = 0;
}
cout << ans;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tc = 1;
//cin >> tc;
while (tc--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Execution timed out |
1085 ms |
336 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
8 ms |
1616 KB |
Output is correct |
4 |
Correct |
14 ms |
3156 KB |
Output is correct |
5 |
Correct |
15 ms |
3152 KB |
Output is correct |
6 |
Correct |
14 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
3 ms |
592 KB |
Output is correct |
3 |
Correct |
10 ms |
2128 KB |
Output is correct |
4 |
Correct |
16 ms |
3892 KB |
Output is correct |
5 |
Correct |
20 ms |
3920 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
592 KB |
Output is correct |
4 |
Correct |
8 ms |
2128 KB |
Output is correct |
5 |
Correct |
16 ms |
3920 KB |
Output is correct |
6 |
Correct |
17 ms |
4092 KB |
Output is correct |
7 |
Correct |
1 ms |
508 KB |
Output is correct |
8 |
Correct |
3 ms |
848 KB |
Output is correct |
9 |
Correct |
10 ms |
2384 KB |
Output is correct |
10 |
Correct |
19 ms |
4432 KB |
Output is correct |
11 |
Correct |
18 ms |
4688 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Execution timed out |
1067 ms |
336 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Execution timed out |
1085 ms |
336 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |