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. 关于ARGB_8888、ALPHA_8、ARGB_4444、RGB_565的理解

    关于ARGB_8888.ALPHA_8.ARGB_4444.RGB_565的理解 A:透明度 R:红色 G:绿 B:蓝 Bitmap.Config ARGB_4444:每个像素占四位,即A=4,R=4 ...

  2. logstash过滤配置

    input { redis { host => "127.0.0.1" port => 6380 data_type => "list" ke ...

  3. android 自定义TODO

    1.找到setting -> editor -> TODO 2. 正则的写法参考以前的就可以 这样我们就可以自己写一个todo了 3.TODO过滤: 4. 然后选择要展示的TODO 这里就 ...

  4. python 压缩每周生成的数据文件

    为了便于整理部分业务数据,以及存储管理, 写了此脚本.后期如果有需求,再改一下. #!/usr/bin/env python #coding:utf8 import os,sys,time,comma ...

  5. supervisor简洁用例

    supervisor是什么 superviosr是一个Linux/Unix系统上进程监控和管理的工具,它由python编写,可以用pip安装.supervisor能将一个普通的命令行进程变为后台dae ...

  6. 50、多线程创建的三种方式之实现Runnable接口

    实现Runnable接口创建线程 使用Runnable创建线程步骤: package com.sutaoyu.Thread; //1.自定义一个类实现java.lang包下的Runnable接口 cl ...

  7. D - Balanced Ternary String (贪心)

    题目链接:http://codeforces.com/contest/1102/problem/D 题目大意:给你一个字符串,这个字符串是由0,1,2构成的,然后让你替换字符,使得在替换的次数最少的前 ...

  8. 已知可生成0~4的rand5(),实现生成0~6的rand7()

    若已知生成0~6的rand7(),求生成0~4的rand5(),则一个方法就是不断生成0~7的数,直到这个数满足0~4就返回. int rand5(){ int res; do{ res = rand ...

  9. 60、二叉搜索树的第k个结点

    一.题目 给定一颗二叉搜索树,请找出其中的第k大的结点.例如, 5 / \ 3 7 /\ /\ 2 4 6 8 中,按结点数值大小顺序第三个结点的值为4. 二.解法 package algorithm ...

  10. Linux触摸屏驱动测试程序范例【转】

    转自:http://blog.sina.com.cn/s/blog_4b4b54da0102viyl.html 转载2015-05-09 16:28:27 标签:androiditlinux 触摸屏驱 ...