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 网络编程(一)InetAddress
package cn.sasa.net; import java.net.InetAddress; import java.net.UnknownHostException; public class ...
- Log4j与Logback
一.Log4j简介: 1.Log4j(log for java) 01.是apache的一个开源项目 02.是使用java语言编写的一个日志框架 03.用于记录程序中的日志信息 04.可以将日志信息输 ...
- MathWorks.MATLAB.NET.Arrays.MWArray”的类型初始值设定项引发异常 解决方法
原因 用的是matlab7运行时,后面又安装了matlab11,后面又重新安装了matlab7运行时,c盘下就有二个运行时的版本了,程序引用了后面的那个,编译后就出上面的问题 解决方法 1重新引用上面 ...
- 简单好用的计算器:bc
1.简单好用的计算器:bc (1)参数: (2)实例: 执行浮点运算和一些高级函数 设定小数精度(数值范围) 进制转换 执行结果为:11000000,这是用bc将十进制转换成二进制 计算平方和平方根:
- wx鼠标拖动事件
#coding:UTF- import wx app = wx.App() def dragEVT(event): if event.ButtonDown(): panel1.SetPosition( ...
- poi 生成图片到excel
try { InputStream iss = new FileInputStream("D:\\test.xlsx"); XSSFWorkbook wb = new XSSFWo ...
- 实例:使用puppeteer headless方式抓取JS网页
puppeteer google chrome团队出品的puppeteer 是依赖nodejs和chromium的自动化测试库,它的最大优点就是可以处理网页中的动态内容,如JavaScript,能够更 ...
- secure CRT常用的查看服务器日志命令
tail -f /(日志文件目录) 查看日志命令ctrl+c停止打印ls -al 查看文件的详细信息路径等vi /(日志文件目录) 打开日志/搜索字符退出:按ESC后,按“:”,输入q, ...
- 如何比sketch和axure更方便地给原型做交互?
在快速的工作环境中,我们现在都希望在工作的各个环节中提高效率.有些产品设计师们做产品原型时,会感觉sketch或者axure添加交互的方式不够快捷.下面就提供一种解决方案. 使用工具:墨刀. 交互链接 ...
- log4j.properties配置详解与实例-全部测试通过[转]
最近使用log4j写log时候发现网上的写的都是千篇一律,写的好的嘛不全,写的全一点的嘛没有一点格式,看着累.这里把网上收集到的整理了一下,并且全部都在机器上测试成功了.这么好的文档估计没有了吧? # ...