#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#define tof_io ios_base::sync_with_stdio(false);cin.tie(0) , cout.tie(0);
#define double long double
#define int long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
const int mod = 1e9+7; //998244353
const long long inf = 1e18;
const int N = 1e3 + 23;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int modplus(int x) {if (x >= mod) {x -= mod;} else if (x < 0) {x += mod;}return x;}
int nc2(int x){x = x * (x+1);return x;}
vector<pair<int, int>> s;
vector<int> h;
vector<int> ps;
vector<int> ks;
int ans = 0;
int res = 0;
void sl(int i){while (s.back().first >= h[i]) {int tmp = (s.back().second - s[s.size() - 2ll].second) % mod;res = modplus(res - tmp * (nc2(s.back().first) / 2 % mod) % mod);s.pop_back();}}
void cal(int i)
{
int tmp = ks[i] % mod;
ans = modplus(ans + res % mod * tmp % mod);
ans = modplus(ans + (nc2(tmp) % nc2(mod)/2 % mod) * (nc2(h[i]) % nc2(mod)/2 % mod) % mod);
res = modplus(res + (nc2(h[i]) / 2 % mod) * tmp % mod);
s.pb(make_pair(h[i], ps[i]));
}
void cand(int i)
{
if (s.back().second != ps[i-1])
{
int tmp = (ps[i - 1] - s.back().second) % mod;
res = modplus(res + tmp * (nc2(h[i]) / 2 % mod) % mod);
s.pb(make_pair(h[i], ps[i - 1]));
}
}
int32_t main()
{
int n;
cin >> n;
h.pb(0);
ps.pb(0);
ks.pb(0);
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
h.pb(x);
}
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
ks.pb(x);
ps.pb(x + ps[i]);
}
s.pb(make_pair(0ll,0ll));
for (int i = 0; i < n; i++)
{
sl(i + 1);
cand(i + 1);
cal(i + 1);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
26 ms |
2700 KB |
Output is correct |
4 |
Correct |
44 ms |
4176 KB |
Output is correct |
5 |
Correct |
46 ms |
4216 KB |
Output is correct |
6 |
Correct |
48 ms |
4340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
996 KB |
Output is correct |
3 |
Correct |
30 ms |
2624 KB |
Output is correct |
4 |
Correct |
59 ms |
4804 KB |
Output is correct |
5 |
Correct |
63 ms |
4808 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
444 KB |
Output is correct |
3 |
Correct |
6 ms |
860 KB |
Output is correct |
4 |
Correct |
30 ms |
2772 KB |
Output is correct |
5 |
Correct |
61 ms |
4552 KB |
Output is correct |
6 |
Correct |
66 ms |
5040 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
1112 KB |
Output is correct |
9 |
Correct |
39 ms |
3052 KB |
Output is correct |
10 |
Correct |
58 ms |
6112 KB |
Output is correct |
11 |
Correct |
58 ms |
6180 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
22 ms |
2564 KB |
Output is correct |
12 |
Correct |
51 ms |
4296 KB |
Output is correct |
13 |
Correct |
44 ms |
4292 KB |
Output is correct |
14 |
Correct |
43 ms |
4292 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
6 ms |
860 KB |
Output is correct |
17 |
Correct |
30 ms |
2772 KB |
Output is correct |
18 |
Correct |
60 ms |
4808 KB |
Output is correct |
19 |
Correct |
62 ms |
4832 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
6 ms |
1276 KB |
Output is correct |
22 |
Correct |
31 ms |
3020 KB |
Output is correct |
23 |
Correct |
57 ms |
6000 KB |
Output is correct |
24 |
Correct |
68 ms |
5996 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
7 ms |
960 KB |
Output is correct |
31 |
Correct |
6 ms |
860 KB |
Output is correct |
32 |
Correct |
28 ms |
2764 KB |
Output is correct |
33 |
Correct |
30 ms |
2772 KB |
Output is correct |
34 |
Correct |
58 ms |
4296 KB |
Output is correct |
35 |
Correct |
57 ms |
4628 KB |
Output is correct |
36 |
Correct |
67 ms |
4660 KB |
Output is correct |
37 |
Correct |
61 ms |
4860 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
60 ms |
4752 KB |
Output is correct |
40 |
Correct |
60 ms |
4676 KB |
Output is correct |
41 |
Correct |
58 ms |
4692 KB |
Output is correct |
42 |
Correct |
62 ms |
5364 KB |
Output is correct |