#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 = s.top().X-p[i].X;
h *= h+1;
h /= 2;
h %= MOD;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
600 KB |
Output is correct |
3 |
Correct |
23 ms |
1600 KB |
Output is correct |
4 |
Correct |
43 ms |
3020 KB |
Output is correct |
5 |
Correct |
44 ms |
3136 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
360 KB |
Output is correct |
3 |
Correct |
5 ms |
596 KB |
Output is correct |
4 |
Correct |
24 ms |
1620 KB |
Output is correct |
5 |
Correct |
42 ms |
3048 KB |
Output is correct |
6 |
Correct |
44 ms |
3124 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
5 ms |
596 KB |
Output is correct |
9 |
Correct |
23 ms |
1876 KB |
Output is correct |
10 |
Correct |
43 ms |
3740 KB |
Output is correct |
11 |
Correct |
43 ms |
3836 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |