noi.ac NOIP2018 全国热身赛 第四场 T2 sort

【题解】
跟51nod 1105差不多。
二分答案求出第L个数和第R个数,check的时候再套一个二分或者用two pointers.
最后枚举ai在b里面二分,找到所有范围内的数,排序后输出。
注意最后找到的数可能多于R-L+1,需要考虑这一点。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define LL long long
#define rg register
#define N 100010
using namespace std;
LL tot,n,l,r,st,ed,mn,mx,a[N],b[N],ans[N];
inline LL read(){
LL k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
inline LL check(LL x){
LL sum=;
for(rg int i=;i<=n;i++){
LL tmp=x-a[i]+;
sum+=lower_bound(b+,b++n,tmp)-b-;
// printf("sum=%d\n",sum);
}
// printf("sum=%d\n",sum);
return sum;
}
int main(){
n=read(); st=read(); ed=read();
for(rg int i=;i<=n;i++) a[i]=read(); sort(a+,a++n);
for(rg int i=;i<=n;i++) b[i]=read(); sort(b+,b++n);
l=a[]+b[]-; r=a[n]+b[n];
while(l+<r){
LL mid=(l+r)>>;
if(check(mid)>=st) r=mid; else l=mid;
}
mn=r;
l=a[]+b[]-; r=a[n]+b[n];
while(l+<r){
LL mid=(l+r)>>;
if(check(mid)>=ed) r=mid; else l=mid;
}
mx=r;
// printf("%d %d\n",mn,mx);
for(rg int i=;i<=n;i++){
int tmp=mn-a[i],tmp2=mx-a[i];
int pos1=lower_bound(b+,b++n,tmp)-b;
if(pos1==n+) continue;
int pos2=upper_bound(b+,b++n,tmp2)-b;
// printf("%d %d\n",pos1,pos2);
for(rg int j=pos1;j<pos2;j++) ans[++tot]=a[i]+b[j];
}
sort(ans+,ans++tot);
tot=min(tot,ed-st+);
for(rg int i=;i<=tot;i++) printf("%lld ",ans[i]);
return ;
}
noi.ac NOIP2018 全国热身赛 第四场 T2 sort的更多相关文章
- NOI.AC NOIP2018 全国热身赛 第四场
心路历程 预计得分:\(0 + 100 +100\) 实际得分:\(10 + 100 + 0\) 神TM T3模数为啥是\(1e9 + 9\)啊啊啊啊,而且我也确实是眼瞎...真是血的教训啊.. T2 ...
- noi.ac NOIP2018 全国热身赛 第四场 T1 tree
[题解] 考虑从小到大枚举边权,按顺序加边. 当前树被分成了若干个联通块,若各个块内的点只能跟块外的点匹配,那么最终的min g(i,pi)一定大于等于当前枚举的边. 判断各个联通块内的点是否全部能跟 ...
- noi.ac NOIP2018 全国热身赛 第二场 T3 color
[题解] 我们可以发现每次修改之后叶子结点到根的路径最多分为两段:一段白色或者黑色,上面接另一段灰色的.二分+倍增找到分界点,然后更新答案即可. check的时候只需要判断当前节点对应的叶子结点的区间 ...
- noi.ac NOIP2018 全国热身赛 第二场 T1 ball
[题解] 可以发现每次推的操作就是把序列中每个数变为下一个数,再打一个减一标记:而每次加球的操作就是把球的位置加上标记,再插入到合适的位置. 用set维护即可. #include<cstdio& ...
- NOI.AC NOIP模拟赛 第四场 补记
NOI.AC NOIP模拟赛 第四场 补记 子图 题目大意: 一张\(n(n\le5\times10^5)\)个点,\(m(m\le5\times10^5)\)条边的无向图.删去第\(i\)条边需要\ ...
- NOI.AC: NOIP2018 全国模拟赛习题练习
闲谈: 最后一个星期还是不浪了,做一下模拟赛(还是有点小虚) #30.candy 题目: 有一个人想买糖吃,有两家商店A,B,A商店中第i个糖果的愉悦度为Ai,B商店中第i个糖果的愉悦度为Bi 给出n ...
- NOIP2018 全国热身赛 第二场 (不开放)
NOIP2018 全国热身赛 第二场 (不开放) 题目链接:http://noi.ac/contest/26/problem/60 一道蛮有趣的题目. 然后比赛傻逼了. 即将做出来的时候去做别的题了. ...
- NOI.AC NOIP模拟赛 第五场 游记
NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ...
- NOI.AC NOIP模拟赛 第六场 游记
NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...
随机推荐
- TCP协议深度刨析
这篇文章主要是详细说明TCP的拥塞控制,因为它对于我们理解整个TCP/IP协议栈非常重要,但我个人能力有限,其中引用了很多网上其他博主的文章,在下文引用处都有说明,主要是让整篇文章能够连贯,不至于让所 ...
- Mac 解登录密码Keychain
在终端输入: security unlock-keychain -p "login pwd" ~/Library/Keychains/login.keychain 在制作macOS ...
- iOS [CIContext initWithOptions:]: unrecognized selector sent to instance 模拟器 iOS 8.4
在模拟器(iPhone 4s,iOS 8.4)中运行应用时, 应用crash在了使用CIContext(options:nil) 这个API的一个纯Swift第三方库. StackOverFlow的解 ...
- the little schemer 笔记(9)
第九章 ...and Again, and Again, and, Again, ... 你想来点鱼子酱吗? 那就去找它吧. (looking a lat)是什么,其中a是 caviar, lat是( ...
- python之使用request模块发送post和get请求
import requestsimport json #发送get请求并得到结果# url = 'http://api.nnzhp.cn/api/user/stu_info?stu_name=小黑马 ...
- fzu Problem 2198 快来快来数一数 (快速幂+优化)
题目链接: Problem 2198 快来快来数一数 题目描述: 给出n个六边形排成一排,a[i]代表i个六边形能组成的生成树个数,设定s[i]等于a[1]+a[2]+a[3]+....+a[i- ...
- Database UVA - 1592
对于每组数据,首先通过一个map将每个字符串由一个数字代替,相同的字符串由相同数字代替,不同的字符串由不同数字代替.那么题目就变为了询问是否存在行r1,r2以及列c1,c2使得str[r1][c1]= ...
- Codeforces Round #322 (Div. 2)
水 A - Vasya the Hipster /************************************************ * Author :Running_Time * C ...
- h5-25-地理定位配合百度地图
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- FACVSPOW - Factorial vs Power 数学方法 + 二分
http://www.spoj.com/problems/FACVSPOW/ 求解n! > a^n最小的整数n 对于有n!和a^n的东西,一般是取ln 然后就是求解 (ln(1) + ln(2) ...