zoukankan      html  css  js  c++  java
  • Codeforces Round #448 (Div. 2) B

    题目描述有点小坑,ij其实是没有先后的 并且y并不一定存在于a中 判断y的个数和所给数组无关 对于2 - 7来说 中间满足%2==0的y一共有3个 2 4 6 这样

    可以看出对于每个数字a 都能够二分出来一个范围resl resr 这个范围内的数字到a 之间一共有k个x的倍数

    然后就是查找一下a数组中有多少数字在resl和resr中间 也是二分寻找

    L n,ds,num;
    
    L a[100050] ;
    
    L fin(L l,L r,L ds) {
        L num1=r/ds;
        L num2=l/ds;
        L nu = num1-num2;
        if(l%ds==0)nu++;
        return nu;
    }
    
    L low(L x) {
        L l=1,r=n;L res=-1;
        while(l<=r){
            L mid=(l+r)/2;
            if(a[mid] >= x){
                res=mid;r=mid-1;
            } else l = mid + 1 ;
        }
        return res ;
    }
    L upp(L x){
        L l=1,r=n;L res=-1;
        while(l<=r){
            L mid=(l+r)/2;
            if(a[mid] <= x){
                res=mid;l=mid+1;
            } else r=mid-1 ;
        }
        return res ;
    }
    
    L check(L ql,L qr) {
        L l = low(ql);
        L r = upp(qr);
        if(l==-1||r==-1) return 0 ;
        if(l>r) return 0 ;
        return r-l+1;
    }
    
    
    int  main () {
        while(scanf("%lld%lld%lld" , &n,&ds,&num) != EOF) {
            rep(i,1,n) a[i] = read() ;
            sort(a+1,a+1+n) ;
            L ans = 0 ;
            rep(i,1,n) {
                L x = a[i] ;
                L l=x,r=1e18 ;
                L resl=-1,resr=-1;
                while(l<=r){
                    L mid=(l+r)/2;
                    L nu = fin(x,mid,ds) ;
                    if(nu == num) {
                        resl=mid;
                        r=mid-1;
                    }
                    else if(nu < num) {
                        l=mid+1;
                    }
                    else {
                        r=mid-1;
                    }
                }
                l=x,r=1e18 ;
                while(l<=r){
                    L mid=(l+r)/2;
                    L nu = fin(x,mid,ds) ;
                    if(nu == num) {
                        resr=mid;
                        l=mid+1;
                    }
                    else if(nu < num) {
                        l=mid+1;
                    }
                    else {
                        r=mid-1;
                    }
                }
                if(resl==-1||resr==-1) continue ;
                L z = check(resl,resr) ;
                ans += z ;
            }
            cout << ans << endl ;
        }
    }
    

    因为室友天天晚上唱歌打牌到一两点。。第二天又要早起去训练赛或者上课。。

    然后这两天都很困。。题看不下去。。头晕晕

    还记得南宁网络赛之前一夜未眠,很困而又睡不着,到了比赛的时候却一点都感觉不到

    就像在网吧连续通宵好几天的人,他们其实应该也是很困的,然而等到游戏开始,就一点也感觉不到了

    但是对于身体的消耗是仍然存在的,连续几天的脑力消耗还是很累的

    还是要好好调整一下啊。。

  • 相关阅读:
    js实现页面跳转,location.href和location.replace和location.reload的区别
    Object.create()和new 创建对象的区别
    apply、call、bind区别、用法
    JavaScript toString() 函数详解
    javascript中this指针详解
    javascript中null 和 undefined的区别
    jQuery 图片轮流展示效果
    min-height 兼容
    css 命名规范
    移动端隐藏手机虚拟键盘
  • 原文地址:https://www.cnblogs.com/rayrayrainrain/p/7909809.html
Copyright © 2011-2022 走看看