E - Superior Periodic Subarrays

好难的一题啊。。。

这个博客讲的很好,搬运一下。

https://blog.csdn.net/thy_asdf/article/details/49406133

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mk make_pair
  6. #define pii pair<int,int>
  7. #define piii pair<int, pair<int,int> >
  8.  
  9. using namespace std;
  10.  
  11. const int N = 2e5 + ;
  12. const int M = + ;
  13. const int inf = 0x3f3f3f3f;
  14. const LL INF = 0x3f3f3f3f3f3f3f3f;
  15. const int mod = 1e9 + ;
  16. const double eps = 1e-;
  17.  
  18. int gcd(int a, int b) {
  19. return !b ? a : gcd(b, a % b);
  20. }
  21.  
  22. int n, mx, a[N << ], cnt[N << ], f[N << ];
  23. bool flag[N << ];
  24.  
  25. int main() {
  26. scanf("%d", &n);
  27. for(int i = ; i < n; i++) {
  28. scanf("%d", &a[i]);
  29. a[i + n] = a[i];
  30. }
  31.  
  32. LL ans = ;
  33. for(int d = ; d < n; d++) { //枚举GCD(n,s)
  34. if(n % d) continue;
  35.  
  36. memset(flag, false, sizeof(flag));
  37.  
  38. for(int k = ; k < d; k++) { //枚举起点
  39. mx = ;
  40. for(int i = k; i < * n; i += d) mx = max(mx, a[i]); //找出这些相隔为d的数之间最大的数
  41. for(int i = k; i < * n; i += d) flag[i] = (a[i] == mx);//判断这个数是不是一系列数的最大值
  42. }
  43.  
  44. f[] = flag[]; //以i结尾的"卓越子序列"最长可能长度
  45. for(int i = ; i < * n; i++) {
  46. if(flag[i]) f[i] = f[i - ] + ;
  47. else f[i] = ;
  48. f[i] = min(f[i], n - );
  49. }
  50.  
  51. cnt[] = ; //1-i中有多少个数与n的gcd为枚举的d
  52. for(int i = ; i < n / d; i++) cnt[i] = cnt[i - ] + (gcd(i, n / d) == );
  53. //要把Gcd(s,n)==d化简成gcd(s/d,n/d)==1,不然会被卡
  54.  
  55. for(int i = n; i < n * ; i++) ans += cnt[f[i] / d];
  56. }
  57.  
  58. printf("%lld\n", ans);
  59. return ;
  60. }
  61. /*
  62. */

Codeforces Round #323 (Div. 2) E - Superior Periodic Subarrays的更多相关文章

  1. Codeforces Round #323 (Div. 1) B. Once Again... 暴力

    B. Once Again... Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/582/probl ...

  2. Codeforces Round #323 (Div. 2) C. GCD Table 暴力

    C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...

  3. 重复T次的LIS的dp Codeforces Round #323 (Div. 2) D

    http://codeforces.com/contest/583/problem/D 原题:You are given an array of positive integers a1, a2, . ...

  4. Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS

    D. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  5. Codeforces Round #323 (Div. 2) C. GCD Table map

    题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...

  6. Codeforces Round #323 (Div. 2) C.GCD Table

    C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is define ...

  7. Codeforces Round #323 (Div. 1) A. GCD Table

    A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #323 (Div. 2) D 582B Once Again...(快速幂)

    A[i][j]表示在循环节下标i开头j结尾的最长不减子序列,这个序列的长度为p,另外一个长度为q的序列对应的矩阵为B[i][j], 将两序列合并,新的序列对应矩阵C[i][j] = max(A[i][ ...

  9. Codeforces Round #323 (Div. 2) C GCD Table 582A (贪心)

    对角线上的元素就是a[i],而且在所在行和列中最大, 首先可以确定的是最大的元素一定是a[i]之一,这让人想到到了排序. 经过排序后,每次选最大的数字,如果不是之前更大数字的gcd,那么只能是a[i] ...

随机推荐

  1. 两个button之间的间距如何去掉

    在外层加上一个父元素,设置font-size:0;即可. 两个按钮之间的间距如何去掉

  2. The Ph.D. Grind

    The Ph.D. Grind A Ph.D. Student Memoir Summary The Ph.D. Grind, a 122-page e-book, is the first know ...

  3. [整理]VS2010中如何添加“依赖","库目录","包含目录"

    VS2010中如何添加“依赖","库目录","包含目录" 1. 添加编译所需要(依赖)的 lib 文件[解决方案资源管理器]“项目->属性-&g ...

  4. 希尔密码(Hill Cipher)的实现

    原理应该不用多讲了,自己百度就可以. C++实现: #include <iostream> #include <string> #include <memory.h> ...

  5. Richard Stallman:让我们关注和尊敬自由软件教父

    1953年,Richard Stallman生于美国纽约曼哈顿区.在度过了并不快乐的童年之后,他在哈佛大学找到了自己的家.在MIT人工智能实验室工作期间,展露出了自己的计算 机天赋.对他来说,开发操作 ...

  6. getElementById()方法取值

    举例子: javascript: var time = document.getElementById('jidu').value; //指定时间 var taskclass = document.g ...

  7. HDU 2095 find your present (2) 动态链表

    解题报告:输入一个n,后面紧跟着输入n个数,输入的这n个数中,除了有一个数的个数为奇数外,其它的数的个数都是偶数个,现在要你找出这个个数为奇数的这个数. 看起来好像很简单的样子,不过,这题的重点不在这 ...

  8. jquery 根据后台传过来的值动态设置下拉框、单选框选中

    更多内容推荐微信公众号,欢迎关注: jquery  根据后台传过来的值动态设置下拉框.单选框选中 $(function(){ var sex=$("#sex").val(); va ...

  9. jQuery动态给下拉列表添加一个选项(创建DOM对象)

    使用的函数:

  10. Linux多线程的使用一:互斥锁

    多线程经常会在Linux的开发中用到,我想把平时的使用和思考记录下来,一是给自己做个备忘,二是分享给可能会用到的人. POSIX标准下互斥锁是pthread_mutex_t,与之相关的函数有: 1 i ...