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][ ...
随机推荐
- 转:JAVA 的wait(), notify()与synchronized同步机制
原文地址:http://blog.csdn.net/zyplus/article/details/6672775 转自:https://www.cnblogs.com/x_wukong/p/40097 ...
- 查找->静态查找表->分块查找(索引顺序表)
文字描述 分块查找又称为索引顺序查找,是顺序查找的一种改进方法.在此查找算法中,除表本身外, 还需要建立一个”索引表”.索引表中包括两项内容:关键字项(其值为该字表内的最大关键字)和指针项(指示该子表 ...
- RENAME方法进行分区改造
1.新建零时表 set time on timing on create table RPTUSER.RPT_TMP_10086BDL_bak ( HANDLEDATE DATE, TEL_CALLI ...
- $(this) 和 this 关键字在 jquery 中有何不同?
$(this) 返回一个 jQuery 对象,你可以对它调用多个 jQuery 方法,比如用 text() 获取文本,用 val() 获取值等等. 而 this 代表当前元素,它是 javascrip ...
- opencv手工编译
opencv手工编译方法1.下载cmake gui2.在where is the source code路径下配置opencv根目录,在where to build the binaries路径下配置 ...
- 实现web消息推送的技术和采用长轮询corundumstudio介绍
实时消息的推送,PC端的推送技术可以使用socket建立一个长连接来实现.传统的web服务都是客户端发出请求,服务端给出响应.但是现在直观的要求是允许特定时间内在没有客户端发起请求的情况下服务端主动推 ...
- what's the 回撤
什么是“回撤”? “回撤”是个谓语,前面隐含了一个主语.一般来说,没有人说“亏损回撤”的,我们说的“回撤”,通常指“股价回撤”.“市值回撤”.“净值回撤”和“盈利回撤”. “股价回撤”是针对个股的,即 ...
- Kubernetes总结
1.Kubernetes简介 在了解Kubernetes之前,我们有必要先简单了解一下传统的运维模式.在传统的项目架构中(单体or微服务),我们一般将项目打包为war或fatJar的方式进行部署. 在 ...
- python web框架介绍对比
Django Python框架虽然说是百花齐放,但仍然有那么一家是最大的,它就是Django.要说Django是Python框架里最好的,有人同意也有人 坚决反对,但说Django的文档最完善.市场占 ...
- confd动态生成配置文件
下载安装confd $ mkdir -p $GOPATH/src/github.com/kelseyhightower $ git clone https://github.com/kelseyhig ...