Card Game Again CodeForces - 818E (双指针)
大意: 给定序列, 求多少个区间积被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 (双指针)的更多相关文章
- Skills CodeForces - 613B (双指针)
大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $cm$ ...
- Codeforces - 466C 双指针
首先要判sum是否是3的整数倍 然后把符合条件的前缀和以及后缀和分别加入到静态vector中 最后扫一下j和k定位在哪然后求总长的差来更新答案 注意i j k至少隔1位,所以lower_bound是s ...
- CodeForces 462B Appleman and Card Game(贪心)
题目链接:http://codeforces.com/problemset/problem/462/B Appleman has n cards. Each card has an uppercase ...
- codeforces 893D Credit Card 贪心 思维
codeforces 893D Credit Card 题目大意: 有一张信用卡可以使用,每天白天都可以去给卡充钱.到了晚上,进入银行对卡的操作时间,操作有三种: 1.\(a_i>0\) 银行会 ...
- Codeforces Round #544 (Div. 3) dp + 双指针
https://codeforces.com/contest/1133/problem/E 题意 给你n个数(n<=5000),你需要对其挑选并进行分组,总组数不能超过k(k<=5000) ...
- Codeforces Round #543 (Div. 2) D 双指针 + 模拟
https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...
- Codeforces Round #513 by Barcelona Bootcamp C. Maximum Subrectangle(双指针+思维)
https://codeforces.com/contest/1060/problem/C 题意 给两个数组,a数组有n个元素,b数组有m个元素,两个数组元素互相相乘形成n*m的矩阵,找一个子矩阵,元 ...
- 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 ...
- 818E - Card Game Again(尺取法)
818E - Card Game Again 题意 给出一个数列,选择连续的一段使得这些数字的乘积是 k 的倍数,问合法的方案数. 分析 尺取法.设 num 为连续的数的乘积,只要对于 k 的每个素因 ...
随机推荐
- 【问题解决】连接mysql 8错误:authentication plugin 'caching_sha2_password
在刚安装好mysql8,使用native连接的时候报错 authentication plugin 'caching_sha2_password'... 首先确保服务已开启,然后通过cmd命令进入my ...
- 在mybatis中resultMap与resultType的区别
MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMapresultType是直接表示返回类型的,而resultMap则是对外部ResultMa ...
- 02:httpd-2.2基础配置
---恢复内容开始--- 9.日志设定 错误日志: ErrorLog logs/error_log //这里使用了相对路径,相对于/etc/httpd/路径 LogLevel warn //定义日志 ...
- javaSE习题 第三章 运算符、表达式和语句
问答: 1.下列System.out.printf的结果是什么? int a=100,x,y; x=++a; y=a--; System.out.printf("%d,%d,%d" ...
- git difftool和mergetool图形化
1.当然是先安装Beyond Compare3 (此处省略安装步骤,自行百度) 2.设置difftool git config --global diff.tool bc3 git config -- ...
- Kali Linux 更新源 操作完整版教程
一.查看kali系统的更新源地址文件 命令: vim /etc/apt/sources.list 上面这是kali官方的更新源: 拓展知识: 一个完整的源包括:deb 和 deb-src:上图源地址是 ...
- MySQL学习(十六)
MySQL高级部分 触发器 触发器是一类特殊的事务,可以监视某种数据操作(insert/update/delete),并触发相关的操作(insert/update/delete) 触发器创建语法之4要 ...
- js常见知识点2.面向对象相关
一.对象的概念 建议回复: 对象是一个整体,对外提供一些功能. 一切具有属性和方法的事物. 一切具有本质特征和行为的物质. 数据类型: 所有的基本数据类型都没有属性和方法. 所 ...
- POJ 3076 Sudoku
3076 思路: dfs + 剪枝 首先,如果这个位置只能填一种字母,那就直接填 其次,如果对于每一种字母,如果某一列或者某一行或者某一块只能填它,那就填它 然后,对于某个位置如果不能填字母了,或者某 ...
- C# DataTable 通过Linq分组
datatable我们是经常使用到的,但是需要对数据进行分组,具体代码如下: var result = dt.AsEnumerable().GroupBy(f => new { type = f ...