题面在这里!

显然一段区间的 mul - sum * k = 0 才合法,然鹅我们发现sum * k 对于本题的数据来说最大才是1e18,也就是说mul必须得<=1e18.

我们不妨从这里入手,因为mul最多只能乘log个>1的数,所以我们用lef[]记录每个数往左第一个不是1的数在哪,于是前后两个位置中间就是一坨子1,讨论一下就好啦。

#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const int maxn=200005;
const ll inf=(ll)1e19; inline int read(){
int x=0; char ch=getchar();
for(;!isdigit(ch);ch=getchar());
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
return x;
} int a[maxn],n,k,lef[maxn];
ll sum,mul,ans,w; inline void solve(){
const int ha=k; for(int i=1;i<=n;i++){
sum=mul=a[i],ans+=(k==1);
for(int pre=i,now=lef[i];;pre=now,now=lef[now]){
w=mul-sum*(ll)k;
if(w>0&&w%ha==0&&w/ha<pre-now) ans++; if(!now||inf/a[now]<mul) break;
mul*=(ll)a[now],sum+=(ll)a[now]+pre-now-1;
ans+=(mul==sum*(ll)k);
}
}
} int main(){
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout); n=read(),k=read();
for(int i=1;i<=n;i++){
a[i]=read();
lef[i]=(a[i-1]!=1?i-1:lef[i-1]);
} solve(); cout<<ans<<endl;
return 0;
}

  

CodeForces - 992D Nastya and a Game的更多相关文章

  1. codeforces#1136E. Nastya Hasn't Written a Legend(二分+线段树)

    题目链接: http://codeforces.com/contest/1136/problem/E 题意: 初始有a数组和k数组 有两种操作,一,求l到r的区间和,二,$a_i\pm x$ 并且会有 ...

  2. Codeforces 1136E - Nastya Hasn't Written a Legend - [线段树+二分]

    题目链接:https://codeforces.com/problemset/problem/1136/E 题意: 给出一个 $a[1 \sim n]$,以及一个 $k[1 \sim (n-1)]$, ...

  3. Codeforces 1136D - Nastya Is Buying Lunch - [贪心+链表+map]

    题目链接:https://codeforces.com/problemset/problem/1136/D 题意: 给出 $1 \sim n$ 的某个排列 $p$,再给出若干 $(x,y)$ 表示当序 ...

  4. Codeforces 1136C - Nastya Is Transposing Matrices

    题目链接:https://codeforces.com/problemset/problem/1136/C 题意: 给出 $n \times m$ 的矩阵 $A,B$,你可以对其中任意某个 $k \t ...

  5. [Codeforces 489E] Nastya and King-Shamans

    [题目链接] http://codeforces.com/contest/992/problem/E [算法] 线段树 + 二分 时间复杂度 : O(NlogN^2) [代码] #include< ...

  6. CodeForces 992C Nastya and a Wardrobe(规律、快速幂)

    http://codeforces.com/problemset/problem/992/C 题意: 给你两个数x,k,k代表有k+1个月,x每个月可以增长一倍,增长后的下一个月开始时x有50%几率减 ...

  7. CodeForces 992B Nastya Studies Informatics + Hankson的趣味题(gcd、lcm)

    http://codeforces.com/problemset/problem/992/B  题意: 给你区间[l,r]和x,y 问你区间中有多少个数对 (a,b) 使得 gcd(a,b)=x lc ...

  8. CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)

    Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month ...

  9. Codeforces 1340F - Nastya and CBS(分块+哈希)

    Codeforces 题面传送门 & 洛谷题面传送门 首先看到这样的数据范围我们可以考虑分块,具体来说,对于每一块我们记录其中的括号是否能完全消掉,以及对其进行括号相消之后的括号序列(显然是一 ...

随机推荐

  1. 代理设计模式iOS开发Demo(示例程序)源代码

        iOS程序源代码下载链接:03-代理设计模式.zip28.3 KB // main.m // //  main.m //  03-代理设计模式 // //  Created by apple ...

  2. hdu 1253 胜利大逃亡(简单题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1253 题目大意:在所给的时间能顺利离开城堡. #include <iostream> #i ...

  3. JDBC+Servlet+JSP实现基本的增删改查(简易通讯录)

    前言: 最近学习JavaWeb的过程中,自己实践练手了几个小项目,目前已经上传到我的Github上https://github.com/Snailclimb/JavaWebProject.目前只上传了 ...

  4. Linux 内核同步之自旋锁与信号量的异同【转】

    转自:http://blog.csdn.net/liuxd3000/article/details/8567070 Linux 设备驱动中必须解决的一个问题是多个进程对共享资源的并发访问,并发访问会导 ...

  5. 比 file_get_contents() 更优的 cURL 详解(附实例)

    PHP 可以使用 file_get_content() 函数抓取网页内容,但却无法进行更复杂的处理,譬如文件的上传或下载. Cookie 操作等等.而 cURL 提供了这些功能. 一.cURL简介 在 ...

  6. ogre 3d游戏开发框架指南

    ogre 3d游戏开发框架指南pdf 附光盘代码 http://www.ddooo.com/softdown/74228.htm OGRE3D游戏开发框架指南.pdf http://vdisk.wei ...

  7. Laravel artisan commands

    使用php artisan list 可以看到artisan的所有命令以及选项. 当然你也可以在此基础上扩展自己的命令. 1. key 1.1 key:generate 这是一个加密秘钥,用于保证安全 ...

  8. [ Linux ] 服务器更换硬盘

    服务器型号:ThinkServer RD650操作系统:Red Hat 6.7业务用途:生产环境监控机 接到机房邮件通知,告知某台服务器硬盘告警,并提供了设备SN号和机柜位置.根据提供想相关信息找到对 ...

  9. windows server 2012 IIS配置之FTP站点

    原文地址:[原创]winserver2012IIS配置之FTP站点作者:hkmysterious   一.实验拓扑: 使server2012客户计算机通过ftp方式从FTP服务器上下载已上传并共享的文 ...

  10. http之post方法 提交数据的四种方法

    http协议中,post方法用来向服务端提交数据, 这里介绍四种方式: application/x-www-form-urlencoded multipart/form-data applicatio ...