#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
ll a, b, c, d, ans;
int main()
{
cin >> a >> b >> c >> d;
if (a <= 0 && 0 <= b)
{
ans += d - c + 1;
if (c <= 0 && 0 <= d)
{
ans += b - a;
}
}
else if (c <= 0 && 0 <= d)
{
ans += b - a + 1;
}
cout << ans;
return 0;
}
B. 异或
60% 做法
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
ll n, m, g, ans;
ll a[N], b[N];
int main()
{
#define endl '\n'
cin.tie(nullptr) -> sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
ans = max(ans, a[i] ^ a[j]);
}
}
cout << ans;
return 0;
}
```
### 100% 做法1
易证答案是由两个最高位不同的数异或而得(否则更劣)。
直接分组枚举。
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
ll n, m, g, ans;
ll a[N], b[N];
int main()
{
cin.tie(nullptr) -> sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
sort(a + 1, a + 1 + n);
for (int i = 0; i <= 60; i++)
{
if ((a[n] >> i) & 1)
{
g = 1LL << i;
}
}
while (a[n] >= g && n > 1)
{
b[++m] = a[n--];
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
ans = max(ans, a[i] ^ b[j]);
}
}
cout << ans;
return 0;
}
```
### 100% 做法2
其实枚举砍掉一半就可以了。
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
ll n, a[N], ans;
int main()
{
#define endl '\n'
cin.tie(nullptr) -> sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
for (int j = 1; j < i; j++)
{
ans = max(ans, a[i] ^ a[j]);
}
}
cout << ans;
return 0;
}
```
## C. 贪心
搞笑,二分啊。
### 伪 100% 做法
为啥 70%?
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
ll n, m;
ll a[N], ans;
bool check(ll mid)
{
ll sum = 0;
for (int i = 1; i <= n; i++)
{
if (mid > a[i])
{
sum += (mid + a[i] - 1) / a[i];
}
}
return sum <= m;
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] == 0)
{
cout << 0;
exit(0);
}
}
ll l = 0, r = 1000000000000LL;
while (l < r)
{
ll mid = (l + r) / 2;
if (check(mid))
{
ans = l;
l = mid + 1;
}
else
{
r = mid;
}
}
cout << ans;
return 0;
}
```
### 100%
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
struct Node
{
ll x, now;
bool operator>(Node other) const
{
return now > other.now;
}
};
ll n, m;
priority_queue<Node, vector<Node>, greater<Node>> q;
int main()
{
#define endl '\n'
cin.tie(nullptr) -> sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
ll x;
cin >> x;
q.push({x, x});
}
while (m > 0)
{
Node x = q.top();
q.pop();
if (x.now == x.x)
{
m--;
}
// cout << x.x << ' ' << x.now << endl;
m--;
x.now += x.x;
q.push(x);
}
ll ans = 1e18;
for (int i = 1; i <= n; i++)
{
Node x = q.top();
q.pop();
ans = min(ans, x.now);
}
cout << ans;
return 0;
}
```