2018省赛赛第一次训练题解和ac代码
第一次就去拉了点思维很神奇的CF题目
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated.
Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons.
The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj if i ≠ j.
Output
Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.
Example
4
1 9
3 1
6 1
7 4
1
7
1 1
2 1
3 1
4 1
5 1
6 1
7 1
3
Note
For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337with power level 42.
其实就是要先sort一次,每次进行二分统计统计其level,但是要输出最小的,找到最大的减一下就行
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int n,b[N];
pair<int,int>a[N];
int main()
{
scanf("%d",&n);
for(int i=; i<n; i++)
scanf("%d%d",&a[i].first,&a[i].second);
sort(a,a+n);
for(int i=; i<n; i++)
{
int t=lower_bound(a,a+n,make_pair(a[i].first-a[i].second,))-a;
if(t) b[i]=b[t-]+;
else b[i]=;
}
printf("%d\n",n-*max_element(b,b+n));
return ;
}
B - Bear and Prime Numbers
Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers x1, x2, ..., xn of length n and mqueries, each of them is characterized by two integers li, ri. Let's introduce f(p) to represent the number of such indexes k, that xk is divisible by p. The answer to the query li, ri is the sum: , where S(li, ri) is a set of prime numbers from segment [li, ri] (both borders are included in the segment).
Help the bear cope with the problem.
Input
The first line contains integer n (1 ≤ n ≤ 106). The second line contains n integers x1, x2, ..., xn (2 ≤ xi ≤ 107). The numbers are not necessarily distinct.
The third line contains integer m (1 ≤ m ≤ 50000). Each of the following m lines contains a pair of space-separated integers, li and ri (2 ≤ li ≤ ri ≤ 2·109) — the numbers that characterize the current query.
Output
Print m integers — the answers to the queries on the order the queries appear in the input.
Example
6
5 5 7 10 14 15
3
2 11
3 12
4 4
9
7
0
7
2 3 5 7 11 4 8
2
8 10
2 123
0
7
Note
Consider the first sample. Overall, the first sample has 3 queries.
- The first query l = 2, r = 11 comes. You need to count f(2) + f(3) + f(5) + f(7) + f(11) = 2 + 1 + 4 + 2 + 0 = 9.
- The second query comes l = 3, r = 12. You need to count f(3) + f(5) + f(7) + f(11) = 1 + 4 + 2 + 0 = 7.
- The third query comes l = 4, r = 4. As this interval has no prime numbers, then the sum equals 0.
这个题目不难的,给你n个数,m次查询,每个操作给你一个区间[l,r],求a[i]能被[l,r]内素数整除的总数。
这个很像上次csa的一道题
#include <bits/stdc++.h>
using namespace std;
const int N=1e7+;
int c[N],a[N],f[N];
int main()
{
int n,m;
scanf("%d",&n);
for(int i=,x; i<n; i++)
scanf("%d",&x),c[x]++;
for(int i=; i<N; i++)
{
a[i]=a[i-];
if(f[i]) continue;
a[i]+=c[i];
for(int j=i+i; j<N; j+=i)
f[j]=,a[i]+=c[j];
}
scanf("%d",&m);
while(m--)
{
int l,r;
scanf("%d%d",&l,&r);
printf("%d\n",a[min(r,N-)]-a[min(l-,N-)]);
}
return ;
}
用一下二分,也进行前缀和优化
#include <bits/stdc++.h>
using namespace std;
const int N=1e7+;
int c[N],dp[N],a[N],f[N];
int main()
{
int n,m,l=,ma=;
scanf("%d",&n);
for(int i=,x; i<n; i++)
scanf("%d",&x),a[x]++,ma=max(ma,x);
for(int i=; i<=ma; i++)
{
if(!f[i])
{
c[l++]=i;
for(int j=i+i; j<=ma; j+=i)f[j]=;
}
}
for(int i=; i<l;i++)
{
for(int j=c[i];j<=ma;j+=c[i])
dp[i]+=a[j];
if(i)dp[i]+=dp[i-];
}
n=l;
scanf("%d",&m);
while(m--)
{
int l,r,x,y;
scanf("%d%d",&l,&r);
x=lower_bound(c,c+n,l)-c;
if(r<=ma)y=upper_bound(c,c+n,r)-c;
else y=n;
printf("%d\n",dp[y-]-dp[x-]);
}
return ;
}
2018省赛赛第一次训练题解和ac代码的更多相关文章
- 2018天梯赛第一次训练题解和ac代码
随着评讲的进行代码和题解会逐步放上来 2018天梯赛第一次训练 1001 : 进制转换 Time Limit(Common/Java):1000MS/10000MS Memory Limit: ...
- 集训队日常训练20181110 DIV2 题解及AC代码
4375: 孪生素数 Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Submit: 324 ...
- 2018 CCPC网络赛
2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...
- 2019 ICPC南昌邀请赛网络赛比赛过程及题解
解题过程 中午吃饭比较晚,到机房lfw开始发各队的账号密码,byf开始读D题,shl电脑卡的要死,启动中...然后听到谁说A题过了好多,然后shl让blf读A题,A题blf一下就A了.然后lfw读完M ...
- ICPC 2018 焦作区域赛
// 2019.10.7 练习赛 // 赛题来源:2018 ICPC 焦作区域赛 // CF链接:http://codeforces.com/gym/102028 A Xu Xiake in Hena ...
- ICPC 2018 亚洲横滨赛 C Emergency Evacuation(暴力,贪心)
ICPC 2018 亚洲横滨赛 C Emergency Evacuation 题目大意 你一个车厢和一些人,这些人都坐在座位上,求这些人全部出去的时间最小值 Solution 题目咋说就咋做 直接模拟 ...
- HDU 6312 - Game - [博弈][杭电2018多校赛2]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6312 Problem Description Alice and Bob are playing a ...
- HDU 6318 - Swaps and Inversions - [离散化+树状数组求逆序数][杭电2018多校赛2]
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6318 Problem Description Long long ago, there was an ...
- 2018 北京区域赛 I - Palindromes (找规律)
题目 HihoCoder - 1878 题目大意 给出k,让求出第k个回文数(k的“长度”不超过1e5) 题解 之前做过类似的题,是统计各阶段的数找到第K个回文数,但这里K太大,需要寻找新的方法. 打 ...
随机推荐
- shell函数的使用
shell函数的使用比较简单,要点包括定义.参数来源.返回值: 在shell函数里,结合read命令,可以实现在执行脚本的过程中让用户选择参数,增强脚本的交互性: 脚本参数在脚本名称后面输入,函数参数 ...
- python爬虫之路——初识基本页面构造原理
通过chrome浏览器的使用简单介绍网页构成 360浏览器使用右键审查元素,Chrome浏览器使用右键检查,都可查看网页代码. 网页代码有两部分:HTML文件和CSS样式.其中有<script& ...
- kubernetes-jenkins CI/CD平台
软件环境:Jenkins + Kubernetes + Git + Maven + Harbor 发布流程设计 工作流程:手动/自动构建-> Jenkins 调度K8S API->动态生成 ...
- js中读取解析json数据
在数据传输流程中,json是以文本,即字符串的形式传递的,而JS操作的是JSON对象,所以,JSON对象和JSON字符串之间的相互转换是关键. JSON字符串: 'var str1 = ' ...
- python之*的魔性用法
1. *在函数中的作用 聚合 在函数定义时聚合 def eat(args): print('我请你吃:',args) eat('蒸羊羔儿') # 输出结果 # 我请你吃: 蒸羊羔儿 打散 在函数执行时 ...
- C09 指针
目录 指针相关概念 指针变量 null指针 指针的算术运算 指针数组 指向指针的指针 传递指针给函数 从函数返回指针 指针相关概念 变量 如果在程序中定义了一个变量,在对程序进行编译时,系统就会为这个 ...
- Windows平台下MySQL常用操作与命令
Windows平台下MySQL常用操作与命令 Windows平台下MySQL常用操作与命令,学习mysql的朋友可以参考下. 1.导出整个数据库 mysqldump -u 用户名 -p --defau ...
- runtime比较全面的总结
类和对象 Objective-C语言是一门动态语言,它将很多静态语言在编译和链接时期做的事放到了运行时来处理.这种动态语言的优势在于:我们写代码时更具灵活性,如我们可以把消息转发给我们想要的对象,或者 ...
- 设置通过Maven创建的工程的JDK的版本,更改conf/settings.xml
eclipse提示警告如下: Build path specifies execution environment J2SE-1.5. There are no JREs installed in t ...
- [JZOJ] 5837.Omeed
先摆出来这个式子 \[ score=A\sum S_i+B\sum S_i\times f(i) \] 先研究\(f\)函数(也就是Combo函数) 显然的有 \[ f(i)=P_i(f(i-1)+1 ...