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的更多相关文章

  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. Github遇到Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.

    警告:为IP地址192.30.252.128的主机(RSA连接的)持久添加到hosts文件中,那就来添加吧! 解决办法: vim /etc/hosts 添加一行:52.74.223.119 githu ...

  2. 牛市必备的三个条件,A股现在还差几个

    1.国家政策 2.中美贸易 3.资金支持 A股变化如神! 自本月10日受美股大跌的影响后,A股先是随之震荡跳水,千股跌停:随后因高层力挺和政策支持而V型反转,集体涨停:接着上演过山车走势,有时涨得令人 ...

  3. [转载]RSA算法详解

    原文:http://www.matrix67.com/blog/archives/5100 数论,数学中的皇冠,最纯粹的数学.早在古希腊时代,人们就开始痴迷地研究数字,沉浸于这个几乎没有任何实用价值的 ...

  4. 谈谈Flash图表中数据的采集

    一般来说flash中的数据是不能被现有技术很容易采集到的,但是也不能谈flash色变,要具体问题具体分析,有些flash是可以通过一些分析发现背后的数据.然后采集就变得很容易了. 具体案例:搜房房价走 ...

  5. 对于最近一星期jsp培训有感

    这周上课是jsp的培训,找的是外面的一个培训机构的讲师,人挺好的,讲的也不错,不过交给我们的任务是一星期做出一个网站模型——新闻发布系统. 由于我们组本科学计算机的人实在太少了,所以这个重担落在我的身 ...

  6. 【leetcode 简单】 第七十四题 缺失数字

    给定一个包含 0, 1, 2, ..., n 中 n 个数的序列,找出 0 .. n 中没有出现在序列中的那个数. 示例 1: 输入: [3,0,1] 输出: 2 示例 2: 输入: [9,6,4,2 ...

  7. linux源码安装nginx

    任务目标:源码安装nginx,作为web服务修改配置文件,让配置生效,验证配置 首先要去官网nginx.org下载一个tar包: tar xvf 解包 进入到解包出来的目录,对configure进行配 ...

  8. linux tar 解压出错

    今天用tar -xzvf php-7.2.3.tar.gz 解压php的tar包时报错 [root@VM_72_37_centos ~]# tar -xzvf php-.tar.gz gzip: st ...

  9. opencv 摄像头

    VideoCapture cap(); if(!cap.isOpened()) ; Mat frame, edges; namedWindow(); for(;;) { cap >> fr ...

  10. linux 安装 Elasticsearch6.4.0详细步骤以及问题解决方案

    1.jdk 安装 参考资料:https://www.cnblogs.com/shihaiming/p/5809553.html 2.elasticsearch 安装 下载:https://artifa ...