Codeforces Round #323 (Div. 2) E - Superior Periodic Subarrays
E - Superior Periodic Subarrays
好难的一题啊。。。
这个博客讲的很好,搬运一下。
https://blog.csdn.net/thy_asdf/article/details/49406133
- #include<bits/stdc++.h>
- #define LL long long
- #define fi first
- #define se second
- #define mk make_pair
- #define pii pair<int,int>
- #define piii pair<int, pair<int,int> >
- using namespace std;
- const int N = 2e5 + ;
- const int M = + ;
- const int inf = 0x3f3f3f3f;
- const LL INF = 0x3f3f3f3f3f3f3f3f;
- const int mod = 1e9 + ;
- const double eps = 1e-;
- int gcd(int a, int b) {
- return !b ? a : gcd(b, a % b);
- }
- int n, mx, a[N << ], cnt[N << ], f[N << ];
- bool flag[N << ];
- int main() {
- scanf("%d", &n);
- for(int i = ; i < n; i++) {
- scanf("%d", &a[i]);
- a[i + n] = a[i];
- }
- LL ans = ;
- for(int d = ; d < n; d++) { //枚举GCD(n,s)
- if(n % d) continue;
- memset(flag, false, sizeof(flag));
- for(int k = ; k < d; k++) { //枚举起点
- mx = ;
- for(int i = k; i < * n; i += d) mx = max(mx, a[i]); //找出这些相隔为d的数之间最大的数
- for(int i = k; i < * n; i += d) flag[i] = (a[i] == mx);//判断这个数是不是一系列数的最大值
- }
- f[] = flag[]; //以i结尾的"卓越子序列"最长可能长度
- for(int i = ; i < * n; i++) {
- if(flag[i]) f[i] = f[i - ] + ;
- else f[i] = ;
- f[i] = min(f[i], n - );
- }
- cnt[] = ; //1-i中有多少个数与n的gcd为枚举的d
- for(int i = ; i < n / d; i++) cnt[i] = cnt[i - ] + (gcd(i, n / d) == );
- //要把Gcd(s,n)==d化简成gcd(s/d,n/d)==1,不然会被卡
- for(int i = n; i < n * ; i++) ans += cnt[f[i] / d];
- }
- printf("%lld\n", ans);
- return ;
- }
- /*
- */
Codeforces Round #323 (Div. 2) E - Superior Periodic Subarrays的更多相关文章
- 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 ...
- 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 ...
- 重复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, . ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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][ ...
- Codeforces Round #323 (Div. 2) C GCD Table 582A (贪心)
对角线上的元素就是a[i],而且在所在行和列中最大, 首先可以确定的是最大的元素一定是a[i]之一,这让人想到到了排序. 经过排序后,每次选最大的数字,如果不是之前更大数字的gcd,那么只能是a[i] ...
随机推荐
- 两个button之间的间距如何去掉
在外层加上一个父元素,设置font-size:0;即可. 两个按钮之间的间距如何去掉
- 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 ...
- [整理]VS2010中如何添加“依赖","库目录","包含目录"
VS2010中如何添加“依赖","库目录","包含目录" 1. 添加编译所需要(依赖)的 lib 文件[解决方案资源管理器]“项目->属性-&g ...
- 希尔密码(Hill Cipher)的实现
原理应该不用多讲了,自己百度就可以. C++实现: #include <iostream> #include <string> #include <memory.h> ...
- Richard Stallman:让我们关注和尊敬自由软件教父
1953年,Richard Stallman生于美国纽约曼哈顿区.在度过了并不快乐的童年之后,他在哈佛大学找到了自己的家.在MIT人工智能实验室工作期间,展露出了自己的计算 机天赋.对他来说,开发操作 ...
- getElementById()方法取值
举例子: javascript: var time = document.getElementById('jidu').value; //指定时间 var taskclass = document.g ...
- HDU 2095 find your present (2) 动态链表
解题报告:输入一个n,后面紧跟着输入n个数,输入的这n个数中,除了有一个数的个数为奇数外,其它的数的个数都是偶数个,现在要你找出这个个数为奇数的这个数. 看起来好像很简单的样子,不过,这题的重点不在这 ...
- jquery 根据后台传过来的值动态设置下拉框、单选框选中
更多内容推荐微信公众号,欢迎关注: jquery 根据后台传过来的值动态设置下拉框.单选框选中 $(function(){ var sex=$("#sex").val(); va ...
- jQuery动态给下拉列表添加一个选项(创建DOM对象)
使用的函数:
- Linux多线程的使用一:互斥锁
多线程经常会在Linux的开发中用到,我想把平时的使用和思考记录下来,一是给自己做个备忘,二是分享给可能会用到的人. POSIX标准下互斥锁是pthread_mutex_t,与之相关的函数有: 1 i ...