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] ...
随机推荐
- Kafka 0.8 Consumer处理逻辑
0.前言 客户端用法: kafka.javaapi.consumer.ConsumerConnector consumer = kafka.consumer.Consumer.createJavaCo ...
- Idea+TestNg配置test-output输出(转)
说明:testNG的工程我是使用eclipse创建的,直接导入到idea中,运行test时不会生产test-output,只能在idea的控制台中查看运行结果,然后到处报告,经过不懈的百度终于找到怎么 ...
- An Insight to References in C++
[An Insight to References in C++] 引用的本质是常指针.占用的内存和指针一样. 参考:http://www.codeproject.com/Articles/13363 ...
- 产品排序 product
评测传送门 [问题描述] 你是一个公司的员工,你会按时间顺序受到一些产品的订单,你需要用一个栈来改变这些订单的顺序(每个产品都必须入栈和出栈一次). 按初始顺序,每次可以将一个产品入栈,或将栈顶产品弹 ...
- Linux IO调度算法
Linux IO调度算法 操作系统的调度 CPU调度 CPU scheduler IO调度 IO scheduler IO调度器的总体目标是希望让磁头能够总是往一个方向移动,移 ...
- node的导入导出
node的每一个文件,都是一个域,那么里面所有的变量都不允许被外界引用,除非导出.要使用外界的变量,也必须使用导入的方式来导入.import 文件路径. css可以直接使用import +文件路径导入 ...
- Linux基础-free窥内存-dd探硬盘
监控内存篇(RAM)-free free指令可以很直观的看到内存的使用情况 free -m指令以单位为MB的方式查看内存的使用情况(free命令读取的文件是/proc/meminfo) 这个表格的解释 ...
- 【算法学习】老算法,新姿势,STL——Heap
“堆”是一个大家很熟悉的数据结构,它可以在\(O(log\;n)\)的时间内维护集合的极值. 这都是老套路了,具体的内部实现我也就不谈了. 我一般来说,都是用queue库中的priority_queu ...
- FPGA设计方法检查表
-----------------------摘自<FPGA软件测试与评价技术> 中国电子信息产业发展研究院 | 编著------------------------------- 文本格 ...
- v8-su-root
1.下载userdebug版本 2.设置模块打开develop options 3.勾选usb debugging 4.adb remount 5.解压SuperSU_N.7z(联系我索取)并push ...