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. linux strncpy()和strcat使用总结

    strcat原型:char *strcat(char *dest,const char *src); 把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0'.src和de ...

  2. 【SQL】SQL Between用法

  3. java之httpClient 3.x、AsyncHttpClient1.9.x使用总结

    首先请大牛们见谅菜鸟重复造轮子的学习方式,本文适合新手看~ 下面使用的同步http是HttpClient 3.X的版本,不过早已不在维护,如果刚开始使用http,建议大家都换成4.X版本,别看下面的有 ...

  4. SQL优化之踩过的坑【一】

    正看资料看的过瘾,突然收到报警,说服务器负载太高,好吧,登录服务器看看,我擦嘞,还能不能愉快的玩耍了?下面是当时的负载情况 看见mysql使用cpu已经到了2000,io没有等待.说明应该没有大的临时 ...

  5. Emmagee——开源Android性能测试工具

    工具:Emmagee作者:孔庆云 网易(杭州)质量保证部 开源地址:https://github.com/NetEase/Emmagee Wiki:https://github.com/NetEase ...

  6. socket 套接字总结

    简单版 服务端 import socket import struct import json import os server_dir = r'E:\Moudule_1\socket练习\serve ...

  7. uploadify3.2.1的参数设置

    $('#file_upload').uploadify({ auto:false, //接受true 或 false两个值,当为true时选择文件后会自动上传:为false时只会把选择的文件增加进队列 ...

  8. 静态文件link 数据库迁移命令 新建app命令

    <link rel="stylesheet" href="/static/bootstrap-3.3.7-dist/css/bootstrap.css"& ...

  9. 4A

    #include <iostream> using namespace std; int main() { int a; cin>>a; if((a>=4) && ...

  10. distpicker省市区插件初始化选中值的问题

    $('#distpicker1').distpicker('destroy')  //当需要重新生成的时候,需要先销毁 $('#distpicker1').distpicker({ province: ...