Codeforces Round #323
div1 C
这题的是给了一个无限循环的子数组,问有多少个 (l,s)l代表起点s代表长度的循环串,使得所有的在原串中的每位都小于等于另外这个串(l<=n,1<=s<n)

像这样,我们可以枚举n的因子,类似寻找素数的那种方法去搞,在一个循环中我们就可以知道这个点可以不可以选择了,然后每次都计算一次这个区间,看有多少个符合
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=;
typedef long long LL;
int phi[maxn],G[maxn];
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
void phi_table(int n,int g)
{
phi[]=;
for(int i=; i<n; i++)if(G[i]!=g)phi[i]=phi[i-];
else phi[i]=phi[i-]+;
}
int a[maxn];
bool use[maxn],ismax[maxn];
int main()
{
int n;
LL ans=;
scanf("%d",&n);
for(int i=;i<=n;i++)G[i]=gcd(i,n);
for(int i=;i<n; i++)
scanf("%d",&a[i]);
for(int i=; i<n; i++)
{
if(n%i!=)continue;
phi_table(n,i);
memset(use,false,sizeof(use));
memset(ismax,false,sizeof(ismax));
for(int j=; j<i; j++)
{
int ma=-;
for(int k=j; k<n; k+=i)ma=max(a[k],ma);
for(int k=j; k<n; k+=i)
if(a[k]==ma)ismax[k]=true;
}
int r=;
for(int j=; j<n; j++)
{
if(r<j)r=j;
while(true){
if(r>=n && (r%n)==j)break;
if(ismax[r%n]==false)break;
else r++;
}
int d=min(n-,r-j);
ans+= phi[d];
} }
printf("%I64d\n",ans);
return ;
}

Codeforces Round #323的更多相关文章
- 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) E - Superior Periodic Subarrays
E - Superior Periodic Subarrays 好难的一题啊... 这个博客讲的很好,搬运一下. https://blog.csdn.net/thy_asdf/article/deta ...
- 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][ ...
随机推荐
- sql server创建临时表的两种写法和删除临时表
--创建.删除临时表 --第一种方式 create table #tmp(name varchar(255),id int) --第二种方式 select count(id) as storyNum ...
- git 命令详细介绍
Git 命令详解 Git的基本命令: git pull:从其他的版本库(既可以是远程的也可以是本地的)将代码更新到本地,例如:'git pull origin master'就是将origin这个版本 ...
- 转:eval(data)和eval("("+data+")")
http://www.w3school.com.cn/jsref/jsref_eval.asp JavaScript eval() 函数:eval() 函数可计算某个字符串,并执行其中的的 JavaS ...
- es6学习笔记入门总结
1.let const block 作用域 let 代替var 来声明块级作用域,没有变量提升,只在块内有作用 const 可以声明一个常量,类似于指针,指向某一个引用,这个常量并非一成不变的,但是不 ...
- 机器学习:K-近邻算法
K-近邻算法 优点:精度高.对异常值不敏感.无数据输入假定.缺点:计算复杂度高.空间复杂度高.使用数据范围:数值型和标称型. k-近邻算法的一般流程 搜集数据:可以使用任何方法.准备数据:距离计算所需 ...
- Nand Flash 驱动框架
框架入口源文件:s3c_nand.c (可根据入口源文件,再按着框架到内核走一遍) 内核版本:linux_2.6.22.6 硬件平台:JZ2440 以下是驱动框架: 以下是驱动代码 s3c_nan ...
- javascript替代Array.prototype.some操作
Array.prototype.some在低版本浏览器好像不太兼容,下列是替代方法 一. for 循环 const initIds: any[] = [1,2,3]; const Ids: any[] ...
- js阻止默认事件,如a标签跳转和事件冒泡
禁止a标签点击跳转 <a href="http://baidu.com" onclick="return false">点我啊</a> ...
- ubuntu上u-boot的编译
1,下载u-boot 2,将Windows中的u-boot复制到ubuntu虚拟机中自定义目录并解压 3,进入该目录cd 4,安装dtc:sudo apt-get install device-tre ...
- VS Code 管理 .NET Core解决方案
本练习要使用Visual studio code完成一个包含多个项目的解决方案,包括类库和Web项目.结合Visual Studio Code和.NET Core CLI,创建项目结构如下: pied ...