Description–
解题思路–
设
h
[
i
]
h[i]
h[i] 是
0
−
i
0-i
0−i 的防具总个数
二分破绽的位置
u
u
u
若
h
[
m
i
d
]
h[mid]
h[mid] 为奇数,则
u
u
u 在
0
−
m
i
d
0-mid
0−mid 之间
反之则在
m
i
d
−
(
2
31
−
1
)
mid-(2^{31} - 1)
mid−(231−1) 之间
代码–
#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;
ll n, t, s[200005], e[200005], d[200005];
ll hll(ll x)
{
ll ss = 0;
for (ll i = 1; i <= n; ++i)
if (s[i] <= x)
ss += (min(x, e[i]) - s[i]) / d[i] + 1;
return ss;
}
void work()
{
ll l = 0, r = 2147483647;
scanf("%lld", &n);
for (ll i = 1; i <= n; ++i)
scanf("%lld%lld%lld", &s[i], &e[i], &d[i]);
if (hll(r) % 2 == 0)
{
printf("There's no weakness.\n");
return ;
}
while (l < r)
{
ll mid = (l + r) / 2;
if (hll(mid) & 1) r = mid;
else l = mid + 1;
}
printf("%lld %lld\n", l, hll(l) - hll(l - 1));
}
int main()
{
scanf("%lld", &t);
for (ll i = 1; i <= t; ++i)
work();
return 0;
}