CodeForces - 992D Nastya and a Game
显然一段区间的 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的更多相关文章
- codeforces#1136E. Nastya Hasn't Written a Legend(二分+线段树)
题目链接: http://codeforces.com/contest/1136/problem/E 题意: 初始有a数组和k数组 有两种操作,一,求l到r的区间和,二,$a_i\pm x$ 并且会有 ...
- Codeforces 1136E - Nastya Hasn't Written a Legend - [线段树+二分]
题目链接:https://codeforces.com/problemset/problem/1136/E 题意: 给出一个 $a[1 \sim n]$,以及一个 $k[1 \sim (n-1)]$, ...
- Codeforces 1136D - Nastya Is Buying Lunch - [贪心+链表+map]
题目链接:https://codeforces.com/problemset/problem/1136/D 题意: 给出 $1 \sim n$ 的某个排列 $p$,再给出若干 $(x,y)$ 表示当序 ...
- Codeforces 1136C - Nastya Is Transposing Matrices
题目链接:https://codeforces.com/problemset/problem/1136/C 题意: 给出 $n \times m$ 的矩阵 $A,B$,你可以对其中任意某个 $k \t ...
- [Codeforces 489E] Nastya and King-Shamans
[题目链接] http://codeforces.com/contest/992/problem/E [算法] 线段树 + 二分 时间复杂度 : O(NlogN^2) [代码] #include< ...
- CodeForces 992C Nastya and a Wardrobe(规律、快速幂)
http://codeforces.com/problemset/problem/992/C 题意: 给你两个数x,k,k代表有k+1个月,x每个月可以增长一倍,增长后的下一个月开始时x有50%几率减 ...
- 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 ...
- 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 ...
- Codeforces 1340F - Nastya and CBS(分块+哈希)
Codeforces 题面传送门 & 洛谷题面传送门 首先看到这样的数据范围我们可以考虑分块,具体来说,对于每一块我们记录其中的括号是否能完全消掉,以及对其进行括号相消之后的括号序列(显然是一 ...
随机推荐
- 面试精选之Promise
常见Promise面试题 我们看一些 Promise 的常见面试问法,由浅至深. 1.了解 Promise 吗? 2.Promise 解决的痛点是什么? 3.Promise 解决的痛点还有其他方法可以 ...
- 【洛谷 P1419】 寻找段落(二分答案,单调队列)
题目链接 开始还以为是尺取.发现行不通. 一看标签二分答案,恍然大悟. 二分一个\(mid\)(实数),把数列里每个数减去\(mid\),然后求前缀和,在用单调队列维护\(sum[i-t\text{~ ...
- Farey Sequence (欧拉函数+前缀和)
题目链接:http://poj.org/problem?id=2478 Description The Farey Sequence Fn for any integer n with n >= ...
- Berland National Library
题目链接:http://codeforces.com/problemset/problem/567/B 题目描述: Berland National Library has recently been ...
- Python 编码问题:出现中文乱码-- (转)
问题描述: 在写Python代码的过程中,有用到需要输出中文的地方(python2.6.5在中文注释的地方就会出错),但是运行后会出错 我的错误显示: SyntaxError: Non-ASCII c ...
- 史诗级Java/JavaWeb学习资源免费分享
黑马内部视频+相关配套学习资料 Java Spring 技术栈构建前后台团购网站 Java SSM开发大众点评后端 欢迎关注微信公众号:Java面试通关手册 回复关键词: "资源分享第一波& ...
- 很重要的处理项目url[www]
http://www.xdowns.com/soft/10/57/2013/Soft_113319.html https://github.com/TricksterGuy/Morphan http: ...
- springboot在不同环境下进行不同的配置
原文链接:http://www.cnblogs.com/java-zhao/p/5469183.html 不同的环境设置一个配置文件,例如:dev(开发)环境下的配置设置在application-de ...
- HTML5晃动DeviceMotionEvent事件
关于devicemotion html5提供了几个新的DOM事件来获得设备物理方向及运动的信息,包括:陀螺仪.罗盘及加速计. 第一个DOM事件是**deviceorientation**,其提供设 ...
- hdu 3488(KM算法||最小费用最大流)
Tour Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...