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>
/// #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;
}
# | 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... |