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太大,需要寻找新的方法. 打 ...
随机推荐
- 键盘各键对应的ASCII码值(包括鼠标和键盘所有的键)
ESC键 VK_ESCAPE (27)回车键: VK_RETURN (13)TAB键: VK_TAB (9)Caps Lock键: VK_CAPITAL (20)Shift键: VK_SHIFT ($ ...
- 枚举转List
将枚举值转为list (name,value) 的形式 /// <summary> /// 获取口味 /// </summary> /// <returns>< ...
- 51nod 1640 天气晴朗的魔法
题目来源: 原创 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 这样阴沉的天气持续下去,我们不免担心起他的健康. 51nod魔法学校近日开展了主题为“天气晴朗 ...
- 【UML】活动图Activity diagram(转)
前言 在UML状态图的总结中说道,活动图和状态图是紧密相关的.它与流程图也有很多相似的地方. 定义 活动图是状态图的一种特殊形式.其中所有或多数状态都是活动状态,而且所有或多数转移都在源状态中的活动完 ...
- 报bug
在打印输出seg的gt数据的时候,出现了gt数据突然很大突然很小的情况,一般这种都是访问了其他内存
- c++ 读取文件 最后一行读取了两次
用ifstream的eof(),竟然读到文件最后了,判断eof还为false.网上查找资料后,终于解决这个问题. 参照文件:http://tuhao.blogbus.com/logs/21306687 ...
- 经常用到的js函数
//获取样式 function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; }else{ retu ...
- [].indexOf.call()学习
今天看到闭包一道题,就是一个li列表,点击列表控制台输出对应的索引.这里考察了var的作用域问题和闭包对外部变量的引用问题,有几种解决方法. html: <ul> <li>te ...
- php curl使用例子
PHP支持的由Daniel Stenberg创建的libcurl库允许你与各种的服务器使用各种类型的协议进行连接和通讯.libcurl目前支持http.https.ftp.gopher.telnet. ...
- centos7无法切换startx
centos光盘安装后,显示命令行模式,通过startx无法进入图形界面? 解决方法:1.使用yum grouplist查看,根据显示的结果采用不同的界面格式,我用的是 yum groupinstal ...