이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
const ll N = 5e5, M = 2e4 + 3, MOD = 1e9 + 7;
const ll FIX = MOD * MOD * 4;
ll P[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
P[0] = 1;
for (int i = 1; i < N; ++i) P[i] = (P[i-1] * 2) % MOD;
int n;
cin >> n;
int a[n+1], b[n+1];
vector<int> v;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
v.pb(a[i]);
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
v.pb(b[i]);
if (b[i] < a[i]) swap(a[i], b[i]);
}
if (n <= 1e4+2) {
ll X[M], Y[M];
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
auto findx = [&](int x) {
return lower_bound(v.begin(), v.end(), x) - v.begin();
};
for (int i = 1; i <= n; ++i) a[i] = findx(a[i]), b[i] = findx(b[i]);
ll ans = 0;
for (int i = 1; i <= n; ++i) {
fill(X, X+M, 0);
fill(Y, Y+M, 0);
int Xmx = 0, Ymx = 0;
for (int j = 1; j < i; ++j) Xmx = max(Xmx, a[j]), X[b[j]]++;
for (int j = 0; j < M; ++j) {
if (j != M-1) X[j+1] += X[j];
X[j] = (Xmx > j ? 0 : P[X[j]]);
}
for (int j = i+1; j <= n; ++j) Ymx = max(Ymx, a[j]), Y[b[j]]++;
for (int j = 0; j < M; ++j) {
if (j != M-1) Y[j+1] += Y[j];
Y[j] = (Ymx > j ? 0 : P[Y[j]]);
}
for (int j = a[i] + 1; j < M; ++j) {
ans += (v[j] - v[a[i]]) * (((X[j] - X[j-1]) * (Y[M-1] - Y[j-1]) + (Y[j] - Y[j-1]) * (X[M-1] - X[j-1]) - (X[j] - X[j-1]) * (Y[j] - Y[j-1]) + FIX) % MOD);
ans %= MOD;
}
for (int j = b[i] + 1; j < M; ++j) {
ans += (v[j] - v[b[i]]) * (((X[j] - X[j-1]) * (Y[M-1] - Y[j-1]) + (Y[j] - Y[j-1]) * (X[M-1] - X[j-1]) - (X[j] - X[j-1]) * (Y[j] - Y[j-1]) + FIX) % MOD);
ans %= MOD;
}
}
cout << ans << '\n';
}
else {
ll ans = 0;
for (int i = 1; i <= n; ++i) {
ans += (P[i-1] - 1) * (P[n-i] - 1) % MOD;
ans %= MOD;
}
cout << ans << '\n';
}
}
# | 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... |