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太大,需要寻找新的方法. 打 ...
随机推荐
- 初识SeekBar
SeekBar拖动条,是Progress的间接子类 <SeekBar android:id="@+id/seekBar1" android:layout_width=&quo ...
- uvm_reg_predictor——寄存器模型(十一)
保存寄存器的值 观察DUT寄存器值的变化. //---------------------------------------------------------------------------- ...
- BandwagonHost 5个数据中心/机房Ping速度测试亲自体验
我们选择Bandwagonhost服务器的原因之一在于有5个数据中心,而且与众多其他VPS不同之处在于可以自己后台切换机房和IP,这样我们 在遇到不满意的速度时候,可以自己切换其他机房更换,而且对于有 ...
- IDEA 官方背景与修改jsp模板以及字体大小
一.官方背景切换 方法一:先打开file找到Settings 如图: 也可以用快捷方式打开:Ctrl+alt+s 打开 找到Editor点击进入 ,再然后找Color Scheme 可以看到如下图 ...
- 【卡常 bitset 分块】loj#6499. 「雅礼集训 2018 Day2」颜色
好不容易算着块大小,裸的分块才能过随机极限数据:然而这题在线的数据都竟然是构造的…… 题目描述 有 $n$ 个数字,第 $i$ 个数字为 $a_i$. 有 $m$ 次询问,每次给出 $k_i$ 个区间 ...
- 【dp】P1077 摆花
基础DP题 题目描述 小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆.通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号.为了在门口展出更多种花,规定第i种花不能超过a ...
- linux系统防火墙关闭
临时关闭防火墙 #systemctl stop firewalld 永久关闭服务端防火墙 #systemctl disabled firewalld getenforce 查询状态 临时 ...
- 【jenkins】jenkins执行nohup java报错
nohup:failed to run command 'java':No such file or directory 这是因为jenkins只认绝对路径.在shell里面有涉及到文件的都应该写成绝 ...
- Python基础——文件操作
写文件 writefile %%writefile ./data/testFile.txt hello python jin tian tian qi bu cuo open覆盖 txt=open(' ...
- Form和ModelForm组件
Form介绍 我们之前在HTML页面中利用form表单向后端提交数据时,都会写一些获取用户输入的标签并且用form标签把它们包起来. 与此同时我们在好多场景下都需要对用户的输入做校验,比如校验用户是否 ...