C - Snuke Festival

....最后想到了,可是不应该枚举a[],这样要二重循环,而应该枚举b[],这样只需一重循环。。。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e5+;
int a[maxn],b[maxn],c[maxn];
int n; int FindLastSmaller(int key)
{
int l=,r=n-;
while(l<=r){
int mid=(l+r)>>;
if(a[mid]>=key) r=mid-;
else l=mid+;
}
return r;
} int FindFirstLarger(int key)
{
int l=,r=n-;
while(l<=r){
int mid=(l+r)>>;
if(c[mid]>key) r=mid-;
else l=mid+;
}
return l;
} int main()
{
cin>>n;
for(int i=;i<n;i++) cin>>a[i];
for(int i=;i<n;i++) cin>>b[i];
for(int i=;i<n;i++) cin>>c[i];
sort(a,a+n);
sort(b,b+n);
sort(c,c+n);
ll ans=;
for(int i=;i<n;i++){
ll p1=FindLastSmaller(b[i]);
ll p2=FindFirstLarger(b[i]);
ans+=(p1+)*(n-p2);
}
cout<<ans<<endl;
return ;
}

lower_bound(),upper_bounder()不能再好用。。。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
int a[maxn], b[maxn], c[maxn];
int n; int main()
{
scanf("%d", &n);
for (int i = ; i < n; i++) scanf("%d", &a[i]);
for (int i = ; i < n; i++) scanf("%d", &b[i]);
for (int i = ; i < n; i++) scanf("%d", &c[i]);
sort(a, a + n);
sort(b, b + n);
sort(c, c + n);
ll ans = ;
for (int i = ; i<n; i++) {
ll p = lower_bound(a, a + n, b[i]) - a;
ll q = upper_bound(c, c + n, b[i]) - c;
ans += p*(n - q);
}
printf("%lld\n", ans);
}

最新文章

  1. java编码解码乱码问题
  2. offer
  3. 使用 CSS3 制作一组超时尚的动画按钮效果
  4. 通过布赛尔曲线以及CAShapeLayer的strokeStart 、strokeEnd 属性来实现一个圆形进度条
  5. c++ 弧度值与角度值的转换
  6. Swift数据类型之整型和浮点型-备
  7. Python快捷键
  8. linux反弹shell
  9. MATLAB 2012b license checkout failed
  10. nuxt.js实战之用vue-i18n实现多语言
  11. Winform-DataGridView
  12. python基础之 编码进阶,文件操作和深浅copy
  13. 随机漂浮图片、右侧上下浮动快捷栏JS
  14. node-inspector调试工具
  15. Nuke的色彩匹配节点思路
  16. hadoop报错:hdfs.DFSClient: Exception in createBlockOutputStream
  17. MariaDB 主从同步与热备(14)
  18. Java 8 日期时间API
  19. Adaptive Thresholding &amp; Otsu’s Binarization
  20. jquery判断元素的子元素是否存在

热门文章

  1. 使用MySQL会话变量实现窗口函数
  2. spring源码学习之容器的扩展(一)
  3. MAC中已有的虚拟环境在pycharm 中进行调用
  4. memcache 拓展
  5. 项目中的那些事---Java反射的应用
  6. 基于HHT和RBF神经网络的故障检测——第二篇论文读后感
  7. spring boot自动配置之jdbc(转)
  8. 2019-9-2-win10-uwp-保存用户选择文件夹
  9. sar磁盘I/O统计数据
  10. 洛谷P1621 集合 [2017年6月计划 数论13]