当前位置:网站首页>CodeForces - 1324D Pair of Topics(二分或双指针)
CodeForces - 1324D Pair of Topics(二分或双指针)
2022-07-07 07:09:00 【moyangxian】
题意:略
题记:
做法一:二分
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int a[N],b[N],c[N];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>b[i],c[i]=a[i]-b[i];
sort(c+1,c+1+n);
ll ans=0;
for(int i=1;i<=n;i++){
if(c[i]<=0) continue;
int p=upper_bound(c+1,c+1+n,-c[i])-c;
ans+=i-p;
}
cout<<ans<<endl;
return 0;
}
做法二:双指针
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int a[N],b[N],c[N];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>b[i],c[i]=a[i]-b[i];
sort(c+1,c+1+n);
ll ans=0;
int l=1,r=n;
while(l<r){
if(c[l]+c[r]>0){
ans+=r-l;
r--;
}
else l++;
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- 第一讲:鸡蛋的硬度
- 2020CCPC威海 J - Steins;Game (sg函数、线性基)
- Install pyqt5 and Matplotlib module
- JS judge whether checkbox is selected in the project
- nlohmann json
- Unity shader (learn more about vertex fragment shaders)
- PLC信号处理系列之开关量信号防抖FB
- 细说Mysql MVCC多版本控制
- How will fashion brands enter the meta universe?
- Where is the answer? action config/Interceptor/class/servlet
猜你喜欢

12、 Sort

战略合作|SubQuery 成为章鱼网络浏览器的秘密武器

Colorbar of using vertexehelper to customize controls (II)

信息安全实验一:DES加密算法的实现

iNFTnews | 时尚品牌将以什么方式进入元宇宙?
![[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景](/img/fd/5e8f74da25d9c5f7bd69dd1cfdcd61.png)
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景

The configuration and options of save actions are explained in detail, and you won't be confused after reading it

Detailed explanation of diffusion model
![[Frida practice]](/img/20/fc68bcf2f55b140d6754af6364896b.png)
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform

# Arthas 简单使用说明
随机推荐
Netease Cloud Wechat applet
Nested (multi-level) childrn routes, query parameters, named routes, replace attribute, props configuration of routes, params parameters of routes
12、 Sort
Loxodonframework quick start
进程和线程的区别
消费互联网的产业链其实是很短的,它仅仅承接平台上下游的对接和撮合的角色
Redis common commands
CDZSC_2022寒假个人训练赛21级(2)
IIS faked death this morning, various troubleshooting, has been solved
flinkcdc 用sqlclient可以指定mysqlbinlog id执行任务吗
Diffusion模型详解
thinkphp3.2信息泄露
Colorbar of using vertexehelper to customize controls (II)
信息安全实验四:Ip包监视程序实现
Unity3d interface is embedded in WPF interface (mouse and keyboard can respond normally)
Detailed explanation of diffusion model
Switching value signal anti shake FB of PLC signal processing series
Kubernetes cluster capacity expansion to add node nodes
用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
农牧业未来发展蓝图--垂直农业+人造肉