This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 0;
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));
//cout << h << " ";
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));
//cout << tren << " ";
tren = mul(tren, h);
sol = add(sol, tren);
//cout << s.top().X << " " << sol << endl;
kol = add(kol, s.top().Y);
s.pop();
}
kol = add(kol, p[i].Y);
s.push({p[i].X, kol});
}
cout << sol;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |