#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);
int n;
pii p[100005];
stack<pii> s;
int add(int x, int y) {
if (x+y < MOD) return x+y;
return x+y-MOD;
}
int mul(int x, int y) {
return (ll)x * (ll)y % MOD;
}
int pot(int x, int y) {
if (y == 0) return 1;
if (y == 1) return x;
int out = pot(x, y/2);
out = mul(out, out);
if (y % 2 == 1) out = mul(out, x);
return out;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> p[i].X;
for (int i = 0; i < n; i++) cin >> p[i].Y;
int sol = 0;
for (int i = 0; i <= n; i++) {
int kol = p[i].Y;
while (s.size() > 0 && s.top().X >= p[i].X) {
ll h = add(p[i].X, 1);
h = add(h, s.top().X);
h = mul(h, s.top().X-p[i].X);
h = mul(h, pot(2, MOD-2));
ll tren = add(kol, kol);
tren = add(tren, s.top().Y);
tren = add(tren, 1);
tren = mul(tren, s.top().Y);
tren = mul(tren, pot(2, MOD-2));
tren = mul(tren, h);
sol = add(sol, tren);
kol = add(kol, s.top().Y);
s.pop();
}
s.push({p[i].X, kol});
}
cout << sol;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
352 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
596 KB |
Output is correct |
3 |
Correct |
21 ms |
1680 KB |
Output is correct |
4 |
Correct |
41 ms |
3028 KB |
Output is correct |
5 |
Correct |
48 ms |
3080 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
608 KB |
Output is correct |
4 |
Correct |
21 ms |
1680 KB |
Output is correct |
5 |
Correct |
43 ms |
2940 KB |
Output is correct |
6 |
Correct |
45 ms |
3136 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
5 ms |
596 KB |
Output is correct |
9 |
Correct |
22 ms |
1872 KB |
Output is correct |
10 |
Correct |
42 ms |
3664 KB |
Output is correct |
11 |
Correct |
42 ms |
3836 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
352 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |