#include <bits/stdc++.h>
#define DIM 100010
#define MOD 1000000007
using namespace std;
long long h[DIM],w[DIM];
deque<pair <long long,long long> > d;
int n,i;
int main (){
cin>>n;
for (i=1;i<=n;i++)
cin>>h[i];
for (i=1;i<=n;i++)
cin>>w[i];
n++;
d.push_back(make_pair(0,0));
long long sol = 0;
for (i=1;i<=n;i++){
long long latime = 0;
while (!d.empty() && h[i] < d.back().first){
long long h_ant = max (h[i],d[d.size()-2].first);
long long dif = (d.back().first - h_ant + MOD) % MOD;
latime = (latime + d.back().second) % MOD;
sol += ( dif * (dif + 1) / 2 % MOD + dif * h_ant % MOD) % MOD * (1LL * latime * (latime+1) / 2 % MOD) % MOD;
sol %= MOD;
d.pop_back();
}
w[i] = (w[i] + latime) % MOD;
if (h[i] == d.back().first)
d.back().second = (d.back().second + w[i]) % MOD;
else d.push_back(make_pair(h[i],w[i]));
}
cout<<(sol+MOD)%MOD;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
41 ms |
1604 KB |
Output is correct |
4 |
Correct |
62 ms |
2884 KB |
Output is correct |
5 |
Correct |
63 ms |
2972 KB |
Output is correct |
6 |
Correct |
67 ms |
2968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
9 ms |
632 KB |
Output is correct |
3 |
Correct |
44 ms |
2020 KB |
Output is correct |
4 |
Correct |
94 ms |
3808 KB |
Output is correct |
5 |
Correct |
92 ms |
3780 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
10 ms |
588 KB |
Output is correct |
4 |
Correct |
46 ms |
2000 KB |
Output is correct |
5 |
Correct |
88 ms |
3776 KB |
Output is correct |
6 |
Correct |
114 ms |
3840 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
10 ms |
752 KB |
Output is correct |
9 |
Correct |
46 ms |
2372 KB |
Output is correct |
10 |
Correct |
90 ms |
5216 KB |
Output is correct |
11 |
Correct |
92 ms |
5392 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
296 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
34 ms |
1604 KB |
Output is correct |
12 |
Correct |
62 ms |
2916 KB |
Output is correct |
13 |
Correct |
64 ms |
2940 KB |
Output is correct |
14 |
Correct |
64 ms |
2904 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
9 ms |
588 KB |
Output is correct |
17 |
Correct |
45 ms |
1988 KB |
Output is correct |
18 |
Correct |
90 ms |
3784 KB |
Output is correct |
19 |
Correct |
117 ms |
3864 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
10 ms |
820 KB |
Output is correct |
22 |
Correct |
46 ms |
2372 KB |
Output is correct |
23 |
Correct |
87 ms |
5248 KB |
Output is correct |
24 |
Correct |
93 ms |
5312 KB |
Output is correct |
25 |
Correct |
1 ms |
300 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
10 ms |
588 KB |
Output is correct |
31 |
Correct |
10 ms |
588 KB |
Output is correct |
32 |
Correct |
43 ms |
1936 KB |
Output is correct |
33 |
Correct |
46 ms |
2016 KB |
Output is correct |
34 |
Correct |
85 ms |
3596 KB |
Output is correct |
35 |
Correct |
85 ms |
3524 KB |
Output is correct |
36 |
Correct |
96 ms |
3668 KB |
Output is correct |
37 |
Correct |
92 ms |
3740 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
91 ms |
3760 KB |
Output is correct |
40 |
Correct |
99 ms |
3764 KB |
Output is correct |
41 |
Correct |
112 ms |
3908 KB |
Output is correct |
42 |
Correct |
95 ms |
4644 KB |
Output is correct |