P11214 【MX-J8-T2】黑洞
赛前没仔细想觉得是绿的,现在还是建议黄吧。
显然,每一维有两个方向,所以
直接枚举复杂度为
我们希望当前的
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5, mod = 1e9 + 7;
int n, a[N], f[N];
pair<int, int> b[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1, x; i <= n; i++) {
cin >> x;
b[i] = {x - 1, i}, b[n + i] = {a[i] - x, i};
}
sort(b + 1, b + 2 * n + 1);
int t = 1, ans = 1, cnt = 0;
for(int i = 2 * n; i >= 1; i--) {
auto [v, id] = b[i];
cnt += !f[id];
if(cnt == n) ans = (ans + 1ll * t * v % mod) % mod;
if(f[id]) t = t * 2 % mod;
f[id] = 1;
}
cout << ans << '\n';
return 0;
}