add some template for ec-final
二维rmq 离线 init O( n*n*logn*logn ) query O(1)
http://www.cnblogs.com/kuangbin/p/3227420.html
求1-n有多少个素数 n = 1e9
#include <bits/stdc++.h>
using namespace std;
namespace acm {
/// count primes between [1..n] (0< n <=1e9)
/// solution: dp
/// d(n, i) means that the number of value whose min prime number is bigger than i in [1..n]
/// d(n, i) = d(n, i-1) if number i is not a prime
/// d(n, i) = d(n, i-1) - d(n/i, i) + d(i, i-1) if number i is a prime
/// complex time: O(n^(3/4)), space: O(n^(1/2))
struct CountPrime {
int solve(int n) {
if (n < ) {
return ;
}
dp[] = ;
int sqrtn = , length = ;
for (; sqrtn <= n / sqrtn; ++sqrtn) {
dp[++length] = sqrtn - ;
}
for (int i = sqrtn - ; i > ; --i) {
int val = n / i;
if (val != i) {
dp[++length] = val - ;
}
}
for (int i = ; i < sqrtn; ++i) {
if (dp[i] == dp[i-]) {
continue;
}
for (int j=length; j>; --j) {
int val = j < sqrtn ? j : n / (length - j + );
if (i > val / i) {
break;
}
int pre_statue_pos = val / i;
if (pre_statue_pos >= sqrtn) {
pre_statue_pos = length - n / pre_statue_pos + ;
}
dp[j] += dp[i-] - dp[pre_statue_pos];
}
}
return dp[length];
}
static const int maxn = 1e5+;
int dp[maxn];
};
} // namespace acm
int main()
{
//freopen("dp.in", "r", stdin);
//freopen("dp.out", "w", stdout);
acm::CountPrime cp;
int n;
while (scanf ("%d", &n) != EOF) {
printf ("%d\n", cp.solve(n));
}
return ;
}
end
add some template for ec-final的更多相关文章
- [MODx] 1. Add Html5 template into the MODx
1. Connet MODx by SSH: Go to the MODx cloud; Find you current user and right click selet Edit Cloud; ...
- DevExpress Add ASPxGridView template columns at runtime
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <%@ Import Namespace ...
- LOJ#6713. 「EC Final 2019」狄利克雷 k 次根 加强版
题目描述 定义两个函数 \(f, g: \{1, 2, \dots, n\} \rightarrow \mathbb Z\) 的狄利克雷卷积 \(f * g\) 为: \[ (f * g)(n) = ...
- 2020 ICPC EC Final西安现场赛游记
也不知道从何说起,也不知道会说些什么,最想表达的就是很累很累. 从第一天去的时候满怀希望,没什么感觉甚至还有一些兴奋.到后来一直在赶路,感觉很疲惫,热身赛的时候觉得马马虎虎,导致热身赛被咕.然后教练就 ...
- tornado 学习笔记9 Tornado web 框架---模板(template)功能分析
Tornado模板系统是将模板编译成Python代码. 最基本的使用方式: t = template.Template("<html>{{ myv ...
- Why we need template on Django ?
Let's create a simple website by django ... step01: django-admin startproject x01 step02: cd x01 ls ...
- WPF DataGrid Custommization using Style and Template
WPF DataGrid Custommization using Style and Template 代码下载:http://download.csdn.net/detail/wujicai/81 ...
- Gym 102056I - Misunderstood … Missing - [DP][The 2018 ICPC Asia-East Continent Final Problem I]
题目链接:https://codeforces.com/gym/102056/problem/I Warm sunshine, cool wind and a fine day, while the ...
- freemarker的template用法
package cn.itcast.ssm.util; import com.alibaba.fastjson.JSONObject; import freemarker.cache.StringTe ...
随机推荐
- 前端构建工具grunt
简单配置grunt 配置gulp还是grunt都是在node的环境下安装的,所以在这之前保证你的node环境已经安装好了! -------------------------------------- ...
- Eval is Devil-MongoDB master/slave上运行Eval遇到的问题
随便写一句,以免有跟我一样的人遇到这个问题. 驱动版本:MongoDB C# Driver 1.7.0 当在Master/Slave集群上使用Eval的时候,Eval操作只会在Master结点上运行, ...
- mariadb日志学习笔记
MySQL日志: 查询日志:query log 慢查询日志: 查询执行时长超过指定时长的查询操作所记录的日志 slow query log 错误日志:包含了服务器启动和关闭的正常信息 二进制日志:包含 ...
- spring(spring boot)笔记
1.查看数据库连接:org.springframework.boot.autoconfigure.jdbc里的public DataSource dataSource() 方法.在这里打断点,可以查看 ...
- nginx安装 nginx: [emerg] getpwnam(“www”) failed 错误
inux 64系统中安装nginx1.3时如果出现错误:nginx: [emerg] getpwnam(“www”) failed解决方法1: 在nginx.conf中 把user nobo ...
- htaccess rewrites重写规则实例
1..htaccess rewrite实例开始部分 Options +FollowSymLinksRewriteEngine OnRewriteBase / 2.把不带www的域名地址重定向到带www ...
- Python核心编程--学习笔记--7--字典和集合
本章介绍Python语言中的映射类型(字典)和集合类型,包括操作符.工厂函数.内建函数与方法. 1 字典 字典是Python中唯一的映射类型——键key直接映射到值value.字典是容器类型,其对象是 ...
- hdu 1026 Ignatius and the Princess I
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1026 Ignatius and the Princess I Description The Prin ...
- 转载:监控每个节点(Indices部分)
集群的健康只是一个方面,它是对整个集群所有方面的一个很高的概括.节点状态的api是另外一个方面,它提供了关于你的集群中每个节点令你眼花缭乱的统计数据. 节点的状态提供了那么多的统计数据,在你很熟悉它们 ...
- squid基础配置
1 2 3 4 5 6 7 8 9 10 vim /etc/squid/squid.conf http_port 192.168.1.12:3128 (可写多个) cache_mem 64MB ...