第一次就去拉了点思维很神奇的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. 【Python图像特征的音乐序列生成】思路的转变

    关于生成网络这边,可能会做一个深度的受限玻尔兹曼机,这样可以保证生成的音乐不会太相似. 情绪识别网络和生成网络的耦合,中间变量可能直接就是一个one-hot向量,用来标注指定的情绪,不做成坐标那种难以 ...

  2. AJAX不能访问MVC后台程序的问题

    AJAX不能访问后台的MVC有可能是MVC的后台程序加入了身份验证[Authorize]标记,这样前台的AJAX虽然结果显示的是4和200但是responsetext的值可以看到是返回了一个配置文件中 ...

  3. UVA 12898 - And Or 与和或 (思路题)

    思路就是有零一变化的位Or以后一定是1,And以后一定是0:那么如果b的二进制更长那么就把包含a的部分全部置为1或0,如果一样长那么就把不同的部分置为1或0. 今天被这题坑的地方:1默认是int,如果 ...

  4. 2018.5.11 Java利用反射实现对象克隆

    package com.lanqiao.demo; /** * 创建人 * @author qichunlin * */ public class Person { private int id; p ...

  5. c++链表-双向链表+增删查改

    基于双向链表的增删改查和排序(C++实现) 双向链表也叫双链表,是链表的一种,它的每个数据结点中都有两个指针,分别指向直接后继和直接前驱.所以,从双向链表中的任意一个结点开始,都可以很方便地访问它的前 ...

  6. java基础—数组

    一.数组的基本概念 数组可以看成是多个相同类型数据组合,对这些数据的统一管理. 数组变量属引用类型,数组也可以看成是对象,数组中的每个元素相当于该对象的成员变量. 数组的元素可以是任何数据类型,包括基 ...

  7. 因 URL 意外地以“/HelloWorld”结束,请求格式无法识别。

    web.config文件中的 <system.web> 节点下加入:<webServices>    <protocols>        <add name ...

  8. python并发编程之进程2(管道,事件,信号量,进程池)

    管道 Conn1,conn2 = Pipe() Conn1.recv() Conn1.send() 数据接收一次就没有了 from multiprocessing import Process,Pip ...

  9. python3与python2的编码问题

    在讲这个问题之前,我们先说说unicode的工作原理.unicode包含了跟全球所有国家编码的映射关系,就是不管你用哪个国家的编码,unicode都能找到它在unicode中的编码.那么无论你用什么编 ...

  10. LeetCode(155) Min Stack

    题目 Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. ...