zoukankan      html  css  js  c++  java
  • 题解 CH0805 【防线】

    题目链接:Link

    Problem

    Solution

    由于题目中提到了奇数位置要么没有,要么有1个,所以若区间[L,R]中有奇数位置,等价于这个区间里的防具数量为奇数个。
    考虑到n只有200000,可以考虑二分奇数点的位置p,然后判断区间[0,p]中的防具的个数。
    显然对于一组防具((s_i,e_i,d_i)),它对于个数的贡献是$Large frac{min(e_i,p)-s_i}{d_i} +1 ( 但要注意:)min(e_i,p)(有可能小于)s_i$,需要特判。

    Code

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int maxn=200005;
    int T,n;
    LL s[maxn],e[maxn],d[maxn],maxe;
    inline LL sum(LL p)
    {
    	LL tot=0;
    	for(int i=0;i<n;i++) if(min(e[i],p)>=s[i]) tot+=(min(e[i],p)-s[i])/d[i]+1;
    	return tot;
    }
    int main()
    {
    #ifdef local
    	freopen("pro.in","r",stdin);
    #endif
    	scanf("%d",&T);
    	while(T-->0)
    	{
    		scanf("%d",&n);
    		maxe=0;
    		for(int i=0;i<n;i++)
    		{
    			scanf("%lld%lld%lld
    ",&s[i],&e[i],&d[i]);
    			maxe=max(maxe,e[i]);
    		}
    		LL L=0,R=maxe+1,M,res=maxe+1;
    		while(L<=R)
    		{
    			M=(L+R)>>1;
    			if(sum(M)&1) res=M,R=M-1;
    			else L=M+1;
    		}
    		if(res==maxe+1) puts("There's no weakness.");
    		else printf("%lld %lld
    ",res,sum(res)-sum(res-1));
    	}
    	return 0;
    }
    
  • 相关阅读:
    省选测试42
    省选测试41
    省选测试40
    省选测试39
    python海龟画图生成星星
    Python-列表简介
    Linux系统中设置默认的Java版本
    虚拟机无线网卡桥接失败
    pycharm设置启动图标
    禁用vscode硬件加速
  • 原文地址:https://www.cnblogs.com/happyZYM/p/11379039.html
Copyright © 2011-2022 走看看