#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
ll h[N], w[N], sum, mod = 1e9 + 7, n, jog, ans;
ll jogap (ll x, ll y) {
ll a1 = (x * (x + 1)) / 2;
a1 %= mod;
ll a2 = y;
ll a3 = y + 1;
if (a2 % 2 == 0) a2 /= 2;
else a3 /= 2;
a2 %= mod;a3 %= mod;
a2 *= a3;
a2 %= mod;
a1 *= a2;
a1 %= mod;
return a1;
}
ll md(ll x){
return x % mod;
}
int main () {
// freopen ("input.txt", "r", stdin);
bool subtask4 = 0, subtask2 = 0;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
if (i > 1 and h[i] != h[i - 1]) {
subtask4 = 1;
}
if (h[i] > 2) subtask2 = 1;
}
for (int i = 1; i <= n; ++i) {
cin >> w[i];
sum += w[i];
}
if (n <= 1000) {
for (int i = 1; i <= n; ++i) {
jog += jogap (h[i], w[i]);
jog = md (jog);
ll mn = h[i];
for (int j = i - 1; j > 0; j--) {
ll sum1 = w[i] + w[j];
mn = min (mn, h[j]);
ll ans = jogap (mn, sum1) - jogap (mn, w[j]) - jogap (mn, w[i]);
while (ans < 0) ans += mod;
jog += ans;
jog = md (jog);
}
}
}
else if (!subtask2) {
ll sum1 = 0;
for (int i = 1; i <= n; ++i) {
if(h[i] == 1) {
if(sum1 > 0) {
ans = jogap (2, sum1) - jogap(1, sum1);
while (ans < 0) ans += mod;
jog += ans;
jog = md(jog);
}
sum1 = 0;
}
else {
sum1 += w[i];
}
}
if(sum1 > 0){
ans = jogap (2, sum1) - jogap(1, sum1);
while (ans < 0) ans += mod;
jog += ans;
jog = md(jog);
}
jog += jogap(1,sum);
jog = md(jog);
}
else if (!subtask4) {
jog = jogap (h[1], sum);
}
else {
for (int i = 1; i <= n; ++i) {
ans = jogap (h[i], sum) - jogap (h[i], sum - w[i]);
while (ans < 0) ans += mod;
jog += ans;
jog %= mod;
sum -= w[i];
}
}
cout << jog;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
37 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 |
0 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 |
30 ms |
348 KB |
Output is correct |
3 |
Correct |
20 ms |
1116 KB |
Output is correct |
4 |
Correct |
40 ms |
1776 KB |
Output is correct |
5 |
Correct |
45 ms |
1888 KB |
Output is correct |
6 |
Correct |
39 ms |
1964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
604 KB |
Output is correct |
3 |
Correct |
27 ms |
1120 KB |
Output is correct |
4 |
Correct |
54 ms |
1876 KB |
Output is correct |
5 |
Correct |
56 ms |
1888 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
34 ms |
460 KB |
Output is correct |
3 |
Correct |
6 ms |
568 KB |
Output is correct |
4 |
Correct |
27 ms |
976 KB |
Output is correct |
5 |
Correct |
54 ms |
1968 KB |
Output is correct |
6 |
Correct |
56 ms |
1824 KB |
Output is correct |
7 |
Correct |
38 ms |
344 KB |
Output is correct |
8 |
Correct |
7 ms |
348 KB |
Output is correct |
9 |
Correct |
41 ms |
1084 KB |
Output is correct |
10 |
Correct |
59 ms |
1820 KB |
Output is correct |
11 |
Correct |
62 ms |
1868 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
38 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
30 ms |
348 KB |
Output is correct |
9 |
Correct |
34 ms |
348 KB |
Output is correct |
10 |
Correct |
38 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
9 ms |
348 KB |
Output is correct |
13 |
Correct |
38 ms |
348 KB |
Output is correct |
14 |
Correct |
36 ms |
348 KB |
Output is correct |
15 |
Correct |
38 ms |
348 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 |
37 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
37 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
444 KB |
Output is correct |
10 |
Correct |
30 ms |
460 KB |
Output is correct |
11 |
Correct |
20 ms |
1116 KB |
Output is correct |
12 |
Correct |
39 ms |
1876 KB |
Output is correct |
13 |
Correct |
39 ms |
1876 KB |
Output is correct |
14 |
Correct |
37 ms |
1872 KB |
Output is correct |
15 |
Correct |
34 ms |
348 KB |
Output is correct |
16 |
Correct |
8 ms |
348 KB |
Output is correct |
17 |
Correct |
27 ms |
988 KB |
Output is correct |
18 |
Correct |
55 ms |
1948 KB |
Output is correct |
19 |
Correct |
56 ms |
1876 KB |
Output is correct |
20 |
Correct |
38 ms |
348 KB |
Output is correct |
21 |
Correct |
7 ms |
604 KB |
Output is correct |
22 |
Correct |
32 ms |
1064 KB |
Output is correct |
23 |
Correct |
68 ms |
1972 KB |
Output is correct |
24 |
Correct |
62 ms |
1876 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
452 KB |
Output is correct |
27 |
Correct |
37 ms |
460 KB |
Output is correct |
28 |
Correct |
37 ms |
432 KB |
Output is correct |
29 |
Correct |
38 ms |
452 KB |
Output is correct |
30 |
Incorrect |
8 ms |
604 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |