[Ybtoj high-efficiency advanced 1.3] [two points] armor arrangement

[Ybtoj high-efficiency advanced 1.3] [two points] armor arrangement

topic

Insert picture description here
Insert picture description here


Problem-solving ideas

Take a look at the data range
cracking o(≧口≦)o It is
impossible to row by bucket.
If pd (2 31 -1) is an even number, then the entire line of defense has no flaws. If
there is a flaw, it will be an odd number
because there is only one
flaw.
If the total number of
armors in this position is odd, the flaw is in the front,
otherwise it is behind.


Code

#include<iostream>
#include<cstdio>
using namespace std;
long long l,r,s[200100],e[200100],d[200100],n,q;
long long pd(long long x)
{
    
    
	 long long sum=0;
	 for (int i=1;i<=n;i++)
	 	 if (s[i]<=x)  //起始点在当前枚举的破绽位置前
	 	    sum+=(min(x,e[i])-s[i])/d[i]+1;  //累计防具
	 return sum;
}
int main()
{
    
    
	scanf("%lld",&q);
	for (int i=1;i<=q;i++)
	{
    
    
		scanf("%lld",&n);
		for (int j=1;j<=n;j++)
		    scanf("%lld%lld%lld",&s[j],&e[j],&d[j]);
		l=0,r=2147483647;
		if (pd(r)%2==0)  //特判
		{
    
    
			printf("There's no weakness.\n");
			continue;
		} 
		while (l<r)
		{
    
    
			  long long mid=(l+r)/2; 
			  if (pd(mid) & 1)
			     r=mid;
			     else l=mid+1; 
		}
		printf("%lld %lld\n",l,pd(l)-pd(l-1));  
	}
	return 0;
} 

Guess you like

Origin blog.csdn.net/qq_45621109/article/details/111994866