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

  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) E - Superior Periodic Subarrays

    E - Superior Periodic Subarrays 好难的一题啊... 这个博客讲的很好,搬运一下. https://blog.csdn.net/thy_asdf/article/deta ...

  9. 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][ ...

随机推荐

  1. LeetCode 897 Increasing Order Search Tree 解题报告

    题目要求 Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the r ...

  2. multiDex分包时指定主dex的class列表

    在gradle中我们使用了如下代码可以将指定类型分配到主dex中: afterEvaluate { tasks.matching { it.name.startsWith('dex') }.each ...

  3. Jenkins tomcat打包启动脚本,待完善

    shell脚本 #!/bin/bashJENKINS_HOME=/usr/local/jenkinsTOMCAT_HOME=/usr/local/jenkins/tomcat-testSHUTDOWN ...

  4. Vue main.js 文件中全局组件注册部分

    在 \src\components\index.js 文件中export组件 import HeaderList from './HeaderList' import HeaderMenu from ...

  5. finecms指定从第几篇文章开始调用5条记录,并调用文章所在栏目

    我们在建站时可能会有具体的要求,比如从第几篇文章开始调用5篇,finecms如何实现呢?用下面一段代码就能完成:num=0,5表示从第一篇开始调用5篇,注意,0代表第一,5表示调用5篇: <a ...

  6. Python3学习之路~4.3 装饰器

    定义:本质是函数,装饰其他函数就是为其他函数添加附加功能. 原则: 不能修改被装饰函数的源代码 不能修改被装饰函数的调用方式 实现装饰器知识储备: 函数即“变量” 高阶函数 把一个函数名当做实参传递给 ...

  7. 003-hive安装

    http://www.aboutyun.com/thread-6902-1-1.html http://www.aboutyun.com/thread-7374-1-1.html

  8. 【SVD、特征值分解、PCA关系】

    一.SVD    1.含义: 把矩阵分解为缩放矩阵+旋转矩阵+特征向量矩阵. A矩阵的作用是将一个向量从V这组正交基向量的空间旋转到U这组正交基向量的空间,并对每个方向进行了一定的缩放,缩放因子就是各 ...

  9. web页面判断是否首次加载

    判断web页面是否是首次加载: if(!window.name){ window.name ='name' this.setState({ note:true })}

  10. 1: 创建一个sap demo项目:

    1:  创建一个项目: