AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 应用
  • 更多
    • 题解
    • 分享
    • 商店
    • 问答
    • 吐槽
  • App
  • 登录/注册

喜欢零(二分查找)

作者: 作者的头像   远方传来风笛 ,  2023-05-27 11:21:26 ,  所有人可见 ,  阅读 66


1


990D9741-1FFA-43F7-AC7F-2FACA2854E64.jpeg

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int N = 200010;
int c2[N],c5[N],s2[N],s5[N];
int n, k;

int main ()
{
    int T;
    cin >> T;
    while(T --){
        cin >> n >> k;
        for(int i = 1; i <= n; i ++)
        {
            c2[i] = c5[i] = 0;
            int x;
            cin >> x;
            while(x % 2 == 0) c2[i] ++, x /= 2;
            while(x % 5 == 0) c5[i] ++, x /= 5;
            s2[i] = s2[i - 1] + c2[i];
            s5[i] = s5[i - 1] + c5[i];
        }
        LL res = 0;
        for(int i = 1; i <= n; i ++){
            int l1 = lower_bound(s2 + i, s2 + 1 + n, s2[i - 1] + k) - s2;
            int r1 = upper_bound(s2 + i, s2 + 1 + n, s2[i - 1] + k) - s2;
            int l2 = lower_bound(s5 + i, s5 + 1 + n, s5[i - 1] + k) - s5;
            int r2 = upper_bound(s5 + i, s5 + 1 + n, s5[i - 1] + k) - s5;
            int L = max(l1, l2), R = max(r1, r2);
            res += max(0, R - L);
        }
        cout << res << endl;
    }
    return 0;
}

0 评论

你确定删除吗?

© 2018-2023 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息