防具布置
题目
解析
发现直接算答案不好做,考虑二分答案
首先先判无解,然后二分答案即可
code:
#include<cstdio>
#define int long long
using namespace std;
inline bool idigit(char x){return (x<'0'|x>'9')?0:1;}
inline int read()
{
int num=0,f=1;
char c=0;
while(!idigit(c=getchar())){if(c=='-')f=-1;}
while(idigit(c))num=(num<<1)+(num<<3)+(c&15),c=getchar();
return num*f;
}
inline void write(int x)
{
int F[20];
int tmp=x>0?x:-x;
if(x<0)putchar('-');
int cnt=0;
while(tmp>0){F[cnt++]=tmp%10+'0';tmp/=10;}
while(cnt>0)putchar(F[--cnt]);
}
inline int min(int x,int y){return x<y?x:y;}
int T,s[200010],e[200010],d[200010],l,r,mid,n,ans;
inline int S(int x){ans=0;for(int i=1;i<=n;++i)if(x>=s[i])ans+=((min(e[i],x)-s[i])/d[i])+1;return ans;}
signed main()
{
T=read();
while(T--)
{
n=read();
for(int i=1;i<=n;++i)s[i]=read(),e[i]=read(),d[i]=read();
if(!(S(2147483647)&1)){puts("There's no weakness.");continue;}
l=0,r=2147483647;
while(l<r)
{
mid=l+r>>1;
if(S(mid)&1)r=mid;
else l=mid+1;
}
write(l),putchar(' '),write(S(l)-S(l-1)),putchar('\n');
}
return 0;
}