zoukankan      html  css  js  c++  java
  • 「APIO2019」奇怪装置

    「APIO2019」奇怪装置

    找到循环就很简单了

    很显然(y)是每(B)次一循环的,对于每个相邻的(y)循环(x)的值均相差(B+1 pmod A)

    因此总的循环就是(B+1)对于(A)的循环乘上(B)

    (frac{A}{gcd(A,B+1)}cdot B)

    知道循环节之后,把查询分成(O(n))个区间,排序之后直接解决即可

    如果使用基数排序即可做到(O(n))

    以下是快排版本

    #include<bits/stdc++.h>
    using namespace std;
    using ll=long long;
    #define mp make_pair
    char IO;
    ll rd(){
    	ll s=0;
    	while(!isdigit(IO=getchar()));
    	do s=(s<<1)+(s<<3)+(IO^'0');
    	while(isdigit(IO=getchar()));
    	return s;
    }
    int n,c,i;
    ll A,B,ans,r=-1,L,R;
    pair <ll,ll> S[2000010];
    int main(){
    	for(n=rd(),A=rd(),B=rd(),A=min(1.0*B*(A/__gcd(A,B+1)),1e18),i=1;i<=n;++i) {
    		L=rd(),R=rd();
    		if(R-L+1>=A) return printf("%lld
    ",A),0;
    		L%=A,R%=A;
    		L<=R?S[++c]=mp(L,R):(S[++c]=mp(L,A-1),S[++c]=mp(0,R));
    	}
    	for(sort(S+1,S+c+1),i=1;i<=c;++i) if(r<=S[i].second) ans+=S[i].second-max(r,S[i].first-1),r=S[i].second;
    	printf("%lld
    ",ans);
    }
    
    
  • 相关阅读:
    luogu P4009 汽车加油行驶问题
    luogu P4015 运输问题
    luogu P2763 试题库问题
    luogu P4011 孤岛营救问题
    luogu P2765 魔术球问题
    linux 网卡
    linux yum错误
    ubuntu登录备注信息
    Ubuntu网卡配置
    linux 走三层内网添加静态路由
  • 原文地址:https://www.cnblogs.com/chasedeath/p/13380148.html
Copyright © 2011-2022 走看看