第一次就去拉了点思维很神奇的CF题目

2018省赛赛第一次训练

# Origin Title
    A CodeForces 607A Chain Reaction
    B CodeForces 385C Bear and Prime Numbers
    C CodeForces 670D2 Magic Powder - 2
    D CodeForces 360B Levko and Array
    E CodeForces 68B Energy exchange
    F CodeForces 24E Berland collider
    G CodeForces 429B Working out
    H CodeForces 329C Graph Reconstruction
    I CodeForces 329D The Evil Temple and the Moving Rocks
    J CodeForces 182E Wooden Fence
    K CodeForces 590D Top Secret Task
    L CodeForces 71E Nuclear Fusion
    M CodeForces 138D World of Darkraft

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

Input
4
1 9
3 1
6 1
7 4
Output
1
Input
7
1 1
2 1
3 1
4 1
5 1
6 1
7 1
Output
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

CodeForces - 385C

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

Input
6
5 5 7 10 14 15
3
2 11
3 12
4 4
Output
9
7
0
Input
7
2 3 5 7 11 4 8
2
8 10
2 123
Output
0
7

Note

Consider the first sample. Overall, the first sample has 3 queries.

  1. 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.
  2. 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.
  3. 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代码的更多相关文章

  1. 2018天梯赛第一次训练题解和ac代码

    随着评讲的进行代码和题解会逐步放上来 2018天梯赛第一次训练 1001 : 进制转换 Time Limit(Common/Java):1000MS/10000MS     Memory Limit: ...

  2. 集训队日常训练20181110 DIV2 题解及AC代码

    4375: 孪生素数  Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByteTotal Submit: 324       ...

  3. 2018 CCPC网络赛

    2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...

  4. 2019 ICPC南昌邀请赛网络赛比赛过程及题解

    解题过程 中午吃饭比较晚,到机房lfw开始发各队的账号密码,byf开始读D题,shl电脑卡的要死,启动中...然后听到谁说A题过了好多,然后shl让blf读A题,A题blf一下就A了.然后lfw读完M ...

  5. ICPC 2018 焦作区域赛

    // 2019.10.7 练习赛 // 赛题来源:2018 ICPC 焦作区域赛 // CF链接:http://codeforces.com/gym/102028 A Xu Xiake in Hena ...

  6. ICPC 2018 亚洲横滨赛 C Emergency Evacuation(暴力,贪心)

    ICPC 2018 亚洲横滨赛 C Emergency Evacuation 题目大意 你一个车厢和一些人,这些人都坐在座位上,求这些人全部出去的时间最小值 Solution 题目咋说就咋做 直接模拟 ...

  7. HDU 6312 - Game - [博弈][杭电2018多校赛2]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6312 Problem Description Alice and Bob are playing a ...

  8. HDU 6318 - Swaps and Inversions - [离散化+树状数组求逆序数][杭电2018多校赛2]

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6318 Problem Description Long long ago, there was an ...

  9. 2018 北京区域赛 I - Palindromes (找规律)

    题目 HihoCoder - 1878 题目大意 给出k,让求出第k个回文数(k的“长度”不超过1e5) 题解 之前做过类似的题,是统计各阶段的数找到第K个回文数,但这里K太大,需要寻找新的方法. 打 ...

随机推荐

  1. 初识AutoCompleteTextView

    AutoCompleteTextView自动补全框继承自TextView和EditView,通过一个下拉框的形式可以补全信息. 可以通过setThreshold()方法指定用户输入多少个字符后开始显示 ...

  2. Autoit3脚本编写举例

    以任务管理器为例 1.首先打开任务管理器 2.点击结束任务操作 第一步打开任务管理器 run("C:\WINDOWS\system32\taskmgr.exe"); 第二步点击结束 ...

  3. 使用nodejs消费SAP Cloud for Customer上的Web service

    Jerry在公众号文章C4C和微信集成系列教程里曾经使用nodejs去消费C4C提供的标准webservice. 看一个具体例子:C4C里Individual Customers可以维护Social ...

  4. 用Python计算最长公共子序列和最长公共子串

    如何用Python计算最长公共子序列和最长公共子串 1. 什么是最长公共子序列?什么是最长公共子串? 1.1. 最长公共子序列(Longest-Common-Subsequences,LCS) 最长公 ...

  5. IE下contentWindow对象与FF、Chrome下的区别

    在ie中frame(iframe)标签通过name和id获取的对象是不同的. 通过name获取的本身就是contentWindow对象.所以 在ie中不用再找contentWindow了 例: let ...

  6. Mybatis中关于OGNL表达式冲突

    注意设计表字段不能用bor  xor  and  band  eq  neq  lt  gt  lte  gte  shl  shr  ushr

  7. PAT (Basic Level) Practise (中文)- 1009. 说反话 (20)

    http://www.patest.cn/contests/pat-b-practise/1009 给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出. 输入格式:测试输入包含一个测试用例,在 ...

  8. MySQL对数据库数据进行复制的基本过程详解

    MySQL对数据库数据进行复制的基本过程详解 这篇文章主要介绍了MySQL对数据库数据进行复制的基本过程,解读了Slave的一些相关配置,需要的朋友可以参考下 复制 复制是从一个MySQL服务器(ma ...

  9. d3.js--04(enter和exit)

    enter() 当DOM数量少于data的数量,或者压根一个都没有的时候,我们一般会希望让程序帮忙创建. <!DOCTYPE html> <html> <head> ...

  10. 笔记--Day2--python基础2

    一.鸡汤 1.提高自我修养 2.人丑就要多读书 3.多走走,开拓眼界 二.目录: 1.列表.元组操作 2.字符串操作 3.字典操作 dict是无序的 key必须是唯一的 4.集合操作 集合是一个无序的 ...