#include <bits/stdc++.h>
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<int>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define int ll
const int MOD = 1000 * 1000 * 1000 + 7;
int N, X[100001], Y[100001];
int solve(int A) {
return ((A * (A + 1ll)) / 2ll) % MOD;
}
int solve(int A, int B) {
return (solve(A) * solve(B)) % MOD;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N;
for(int l = 0; l < N; l++) cin >> X[l];
for(int l = 0; l < N; l++) cin >> Y[l];
int res = 0, temp = 0; stack<pair<int, int>> S;
for(int l = 0; l < N; l++) {
int H = X[l], W = Y[l];
res = (res + solve(H, W)) % MOD;
int K = 0;
while(!S.empty() && S.top().ff >= H) {
K = (K + S.top().ss) % MOD;
temp -= ((solve(S.top().ff) % MOD) * S.top().ss) % MOD;
if(temp < 0) temp += MOD;
W = (W + S.top().ss) % MOD;
S.pop();
}
res = ((res + ((Y[l] * K) % MOD) * solve(H))) % MOD;
res = (res + (temp * Y[l])) % MOD;
S.push({H, W});
temp = (temp + (solve(H) * (W)) % MOD) % MOD;
}
cout << res % MOD << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
13 ms |
1620 KB |
Output is correct |
4 |
Correct |
19 ms |
3020 KB |
Output is correct |
5 |
Correct |
17 ms |
3028 KB |
Output is correct |
6 |
Correct |
17 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
596 KB |
Output is correct |
3 |
Correct |
12 ms |
2000 KB |
Output is correct |
4 |
Correct |
22 ms |
3748 KB |
Output is correct |
5 |
Correct |
25 ms |
3908 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
592 KB |
Output is correct |
4 |
Correct |
13 ms |
2036 KB |
Output is correct |
5 |
Correct |
26 ms |
3812 KB |
Output is correct |
6 |
Correct |
24 ms |
3916 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
4 ms |
852 KB |
Output is correct |
9 |
Correct |
15 ms |
2324 KB |
Output is correct |
10 |
Correct |
28 ms |
5236 KB |
Output is correct |
11 |
Correct |
29 ms |
5324 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
10 ms |
1624 KB |
Output is correct |
12 |
Correct |
21 ms |
2996 KB |
Output is correct |
13 |
Correct |
16 ms |
3024 KB |
Output is correct |
14 |
Correct |
16 ms |
3032 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
11 ms |
2012 KB |
Output is correct |
18 |
Correct |
22 ms |
3732 KB |
Output is correct |
19 |
Correct |
23 ms |
3820 KB |
Output is correct |
20 |
Correct |
1 ms |
360 KB |
Output is correct |
21 |
Correct |
3 ms |
752 KB |
Output is correct |
22 |
Correct |
12 ms |
2428 KB |
Output is correct |
23 |
Correct |
21 ms |
5248 KB |
Output is correct |
24 |
Correct |
21 ms |
5440 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
580 KB |
Output is correct |
32 |
Correct |
11 ms |
2004 KB |
Output is correct |
33 |
Correct |
11 ms |
1980 KB |
Output is correct |
34 |
Correct |
21 ms |
3620 KB |
Output is correct |
35 |
Correct |
23 ms |
3616 KB |
Output is correct |
36 |
Correct |
26 ms |
3688 KB |
Output is correct |
37 |
Correct |
22 ms |
3740 KB |
Output is correct |
38 |
Correct |
0 ms |
324 KB |
Output is correct |
39 |
Correct |
24 ms |
3748 KB |
Output is correct |
40 |
Correct |
22 ms |
3748 KB |
Output is correct |
41 |
Correct |
21 ms |
3916 KB |
Output is correct |
42 |
Correct |
23 ms |
4556 KB |
Output is correct |