题意:略

题记:

做法一:二分

#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;
}

CodeForces - 1324D Pair of Topics(二分或双指针)相关推荐

  1. [Codeforces Round #627]1324D - Pair of Topics[二分]

    1324D - Pair of Topics[二分] time limit per test memory limit per test input output 2 seconds 256 mega ...

  2. CodeForces - 1324D Pair of Topics (分治+排序)

    CodeForces - 1324D Pair of Topics 题目大意: 这题大意ai+aj>bi+bj全在这个式子上,就问你满足的组合有几种, 题目分析: 整理一下,得到(ai-bi)+ ...

  3. CodeForces - 1324D Pair of Topics(思维+二分)

    题目链接:https://vjudge.net/contest/362265#problem/D The next lecture in a high school requires two topi ...

  4. [codeforces 1324D] Pair of Topics 分而治之+排列组合

    Codeforces Round #627 (Div. 3)   比赛人数6434 [codeforces 1324C]  Frog Jumps   一直向右+边界处理 总目录详见https://bl ...

  5. Codeforces 1324D Pair of Topics

    题目链接:https://codeforces.com/contest/1324/problem/D 题目描述 有两个长度为 n 的数组 A, B.问有多少对 (i,j) 满足 i < j 且 ...

  6. cf 1324D. Pair of Topics

    D. Pair of Topics 题意:给定ab序列,问i<j且ai+aj>bi+bj的对数. 转化:ai-bi<-(aj-bj) 一开始拿到题目想着sort,但是发现i<j ...

  7. Codeforces 359D Pair of Numbers | 二分+ST表+gcd

    题面: 给一个序列,求最长的合法区间,合法被定义为这个序列的gcd=区间最小值 输出最长合法区间个数,r-l长度 接下来输出每个合法区间的左端点 题解: 由于区间gcd满足单调性,所以我们可以二分区间 ...

  8. CodeForces - 1324 D. Pair of Topics 思维+多解法

    CodeForces - 1324 D. Pair of Topics 原题地址: http://codeforces.com/contest/1324/problem/D 基本题意: 给你一个数组, ...

  9. Codeforces1324D Pair of Topics (思维 + 二分)

    题目链接: Pair of Topics 大致题意 给定两个数组a和b, 要求找出所有满足i < j 并且 ai + aj > bi + bj 的所有数对. 解题思路 我们不难想到先对等式 ...

最新文章

  1. Spring3.2.0-mybatis3.2.0 基于全注解搭建的后台框架-基础版
  2. 安装fiddler做代理,本地开发手机端看效果
  3. 用gameMaker做个小游戏
  4. map初始化_您可曾这样初始化一个map呢?
  5. oracle leg函数,oracle对象 约束索引 游标 函数
  6. 职业学校计算机主要学什么条件,职业学校计算机教学计划
  7. oopc——6.oopc的好处
  8. 台积电CEO魏哲家:3nm工艺按计划推进 明年一季度将看到营收
  9. 求众数leetcode(169)+投票算法
  10. 入门 ggplot2 的图形语法
  11. 在linux系统上启动oracle的服务
  12. Python安装指南
  13. 图解TCPIP 学习笔记(一)
  14. 2014年南京航空航天大学计算机学院推荐研究生公示,2014年南航计算机科学与技术学院考研分数线及复试调剂办法...
  15. usb网卡android驱动+win7,usb网卡万能驱动_手把手教你usb网卡驱动
  16. [高通SDM450][Android9.0]PL2303G驱动升级
  17. 计算机图形学实用教程苏小红,计算机图形学实用教程(第4版)
  18. 51单片机流水灯和蜂鸣器同步
  19. 22届哈工大深圳计算机854考研经验贴、过程总结贴(初试 353 复试 304 上岸哈工大深圳)
  20. 通过 api 调用检查具体日期是否为法定节假日

热门文章

  1. 酷睿i7 11800h相当于什么水平 i711800h属于哪个档次
  2. WPF 入门教程(一)
  3. Oracle导出DMP文件的两种方法
  4. Java消息队列三道面试题详解
  5. Excel实用技巧-如何批量提取excel工作表名称
  6. C#属性简写用法 {get;set}
  7. 大数据技术_ 基础理论 之 大数据概念与应用
  8. tv电视焦点(遥控器)操作笔记jq
  9. 【OpenCV3】直线拟合--FitLine()函数详解
  10. C++11之decltype