大意: 给定序列, 求多少个区间积被k整除.

整除信息满足单调性, 显然双指针. 具体实现只需要考虑k的素数向量, 对每一维维护个指针即可.

这题看了下cf其他人的做法, 发现可以直接暴力, 若当前的前缀积模k为0, 暴力向前求出第一个后缀积为0的位置即可, 复杂度是$O(n)$的并且相当好写.

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n, k;
int p[11], f[11], cnt;
int g[N][11], cur[11], sum[11]; int main() {
scanf("%d%d", &n, &k);
int mx = sqrt(k+0.5);
REP(i,2,mx) if (k%i==0) {
p[++cnt] = i;
while (k%i==0) k/=i,++f[cnt];
}
if (k>1) p[++cnt]=k,++f[cnt];
REP(j,1,n) {
scanf("%d", &k);
REP(i,1,cnt) if (k%p[i]==0) {
while (k%p[i]==0) ++g[j][i],k/=p[i];
}
}
ll ans = 0;
int now = 0;
REP(i,1,n) {
REP(j,1,cnt) {
while (cur[j]<n&&sum[j]<f[j]) sum[j]+=g[++cur[j]][j];
if (sum[j]<f[j]) {
printf("%lld\n", ans);
return 0;
}
now = max(now, cur[j]);
}
now = max(now, i);
ans += n-now+1;
REP(j,1,cnt) sum[j]-=g[i][j];
}
printf("%lld\n", ans);
}

Card Game Again CodeForces - 818E (双指针)的更多相关文章

  1. Skills CodeForces - 613B (双指针)

    大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $cm$ ...

  2. Codeforces - 466C 双指针

    首先要判sum是否是3的整数倍 然后把符合条件的前缀和以及后缀和分别加入到静态vector中 最后扫一下j和k定位在哪然后求总长的差来更新答案 注意i j k至少隔1位,所以lower_bound是s ...

  3. CodeForces 462B Appleman and Card Game(贪心)

    题目链接:http://codeforces.com/problemset/problem/462/B Appleman has n cards. Each card has an uppercase ...

  4. codeforces 893D Credit Card 贪心 思维

    codeforces 893D Credit Card 题目大意: 有一张信用卡可以使用,每天白天都可以去给卡充钱.到了晚上,进入银行对卡的操作时间,操作有三种: 1.\(a_i>0\) 银行会 ...

  5. Codeforces Round #544 (Div. 3) dp + 双指针

    https://codeforces.com/contest/1133/problem/E 题意 给你n个数(n<=5000),你需要对其挑选并进行分组,总组数不能超过k(k<=5000) ...

  6. Codeforces Round #543 (Div. 2) D 双指针 + 模拟

    https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...

  7. Codeforces Round #513 by Barcelona Bootcamp C. Maximum Subrectangle(双指针+思维)

    https://codeforces.com/contest/1060/problem/C 题意 给两个数组,a数组有n个元素,b数组有m个元素,两个数组元素互相相乘形成n*m的矩阵,找一个子矩阵,元 ...

  8. Codeforces Round #228 (Div. 1) C. Fox and Card Game 博弈

    C. Fox and Card Game 题目连接: http://codeforces.com/contest/388/problem/C Description Fox Ciel is playi ...

  9. 818E - Card Game Again(尺取法)

    818E - Card Game Again 题意 给出一个数列,选择连续的一段使得这些数字的乘积是 k 的倍数,问合法的方案数. 分析 尺取法.设 num 为连续的数的乘积,只要对于 k 的每个素因 ...

随机推荐

  1. vim插件的安装方式 -- vim注释插件和doxygen函数注释生成插件-ctrlp插件-tabular等号对齐 插件

    使用unzip的时候 指定 -d选项, 是说明解压到的 目标地址. 这个参数还是比较方便的, 比直接unzip到当前目录, 然后在去拷贝到目标目录, 然后再删除当前目录中的解压文件夹, 方便多了. 使 ...

  2. SpringBoot Redis使用fastjson进行序列化

    在使用spring-data-redis,默认情况下是使用org.springframework.data.redis.serializer.JdkSerializationRedisSerializ ...

  3. 【Spring Security】四、自定义页面

    在前面例子中,登陆页面都是用的Spring Security自己提供的,这明显不符合实际开发场景,同时也没有退出和注销按钮,因此在每次测试的时候都要通过关闭浏览器来注销达到清除session的效果. ...

  4. (zhuan) Variational Autoencoder: Intuition and Implementation

    Agustinus Kristiadi's Blog TECH BLOG TRAVEL BLOG PORTFOLIO CONTACT ABOUT Variational Autoencoder: In ...

  5. TIM定时器的应用

    TIM定时器的应用   ①输入捕获的应用: 上一节,我已阐述TIM的输入捕获具体作用有两个(如下图):     对输入信号的测量:                                    ...

  6. 洛谷P1803 凌乱的yyy dp

    我要日更嘤嘤嘤>_< 原题戳>>https://www.luogu.org/problem/show?pid=1803<<(其实是戳不动的,复制粘贴吧) 题目背景 ...

  7. 根据元素取两个list<T>不同

    var aa = ltB.FindAll(b => ltA.Any(a => a.PolicyNo == b.ID)); //得出不同 var expectedList = ltB.Exc ...

  8. Tarjan模板题——牛的舞会

    题目描述 约翰的N (2 <= N <= 10,000)只奶牛非常兴奋,因为这是舞会之夜!她们穿上礼服和新鞋子,别 上鲜花,她们要表演圆舞. 只有奶牛才能表演这种圆舞.圆舞需要一些绳索和一 ...

  9. Android Studio 使用USB真机调试教程

    允许安装未知来源的软件 允许USB调试 设置启动方式 选择USB device 然后运行 会自动安装软件启动! 参考: https://blog.csdn.net/fubo1990/article/d ...

  10. django Admin文档生成器

    Django的admindocs应用可以从模型.视图.模板标签等地方获得文档内容. 一.概览 要激活admindocs,请按下面的步骤操作: 在INSTALLED_APPS内添加django.cont ...