codeforces475D——CGCDSSQ
来源:互联网 发布:网络医院预约挂号系统 编辑:程序博客网 时间:2024/06/05 00:47
1、题意:多次求区间gcd是x的区间数
2、分析:看起来下不了手!管他呢,上暴力,把所有的可能都给他搞出来。每次加入一个数,就把前面的数都和他gcd一下加进去,用map统计数量,最后询问啥输出啥就行。真是可怕,暴力AC了,但是复杂度有保证!可以尝试的证一证。可以证出复杂度是
#include <map>#include <set>#include <cmath>#include <queue>#include <vector>#include <bitset>#include <string>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define M 1000010#define LL long long#define MOD 1000000007#define inf 2147483647#define llinf 4000000000000000000ll#define For(i, x, y) for(int i = (x); i < (y); i ++)#define rep(i, x, y) for(int i = (x); i <= (y); i ++)#define drep(i, x, y) for(int i = (x); i >= (y); i --)inline int read(){ char ch=getchar();int x=0,f=1; while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}inline LL llread(){ char ch=getchar();LL x=0,f=1; while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}map<int, LL> now[2], res;inline int gcd(int x, int y){ return y == 0 ? x : gcd(y, x % y); }int main(){ //freopen("0input.in", "r", stdin); int n = read(), thi = 0; rep(i, 1, n){ int x = read(); now[thi ^ 1].clear(); now[thi ^ 1][x] ++; res[x] ++; for(map<int, LL> :: iterator it = now[thi].begin(); it != now[thi].end(); it ++){ now[thi ^ 1][gcd(x, it -> first)] += it -> second; res[gcd(x, it -> first)] += it -> second; } thi ^= 1; } int q = read(); while(q --){ int x = read(); printf("%I64d\n", res[x]); } return 0;}
0 0
- codeforces475D——CGCDSSQ
- Codeforces475D-CGCDSSQ
- [题解]codeforces475d CGCDSSQ
- [Codeforces475D]CGCDSSQ(数学相关+二分)
- CF475D. CGCDSSQ
- 【codeforces】 475D CGCDSSQ
- Codeforce P471D CGCDSSQ
- rmq cf CGCDSSQ
- Codeforces 475 D. CGCDSSQ
- CodeForces 475D CGCDSSQ
- 【CODEFORCES】 D. CGCDSSQ
- CodeForces 475D CGCDSSQ
- Codeforces457-D. CGCDSSQ
- CodeForces 475D CGCDSSQ RMQ
- Codeforces 475D CGCDSSQ 题解
- CF - 475 - D. CGCDSSQ(枚举)
- codeforces 475D CGCDSSQ ST表+二分
- CF 475D CGCDSSQ 枚举,思维+gcd
- LeetCode Learning 6
- 早产的年终总结
- NOIP 2015 试做
- SVN
- HDU5685Problem A(逆元)
- codeforces475D——CGCDSSQ
- 周赛总结(11.13)
- 初始化整形数组 初始化双精度型数组
- LeetCode 282. Expression Add Operators
- java计算文件大小三种方法以及优缺点比较
- Java学习之二-Java反射机制
- IntelliJ IDEA中怎么查看文件中所有方法(类似eclipse里面的outline)
- MySql中时间类型无法设置默认0000-00-00的解决方法
- 通讯录程序(链表版)