二分水题,A,B,C三个数组排序,对于每个B[i],二分算出来有多少A比他小,多少C比他大,然后扫一遍出结果。O(nlog(n))水过。

#include <bits/stdc++.h>
using namespace std; const int MAXN = 1e5+10;
int A[MAXN],B[MAXN],C[MAXN];
int n;
//严格小于B[i]的数字个数 和 严格大于B[i]的数字个数
long long lnb[MAXN],unb[MAXN]; int main()
{
ios::sync_with_stdio(false);
cin >> n;
for(int i = 0; i < n; ++i)
cin >> A[i];
sort(A,A+n);
for(int i = 0; i < n; ++i)
cin >> B[i];
sort(B,B+n);
for(int i = 0; i < n; ++i)
cin >> C[i];
sort(C,C+n); //对于每个b,先统计出来几个a比他小,O(nlog(n))
for(int i = 0; i < n; ++i)
lnb[i] = lower_bound(A,A+n,B[i]) - A;
for(int i = 0; i < n; ++i)
unb[i] = n - (upper_bound(C,C+n,B[i]) - C);
long long res = 0;
for(int i = 0; i < n; ++i)
res += lnb[i]*unb[i];
cout << res << endl;
return 0;
}

AtCoder Beginner Contest 077 C Snuke Festival(二分)的更多相关文章

  1. AtCoder Regular Contest 084 C - Snuke Festival【二分】

    C - Snuke Festival ....最后想到了,可是不应该枚举a[],这样要二重循环,而应该枚举b[],这样只需一重循环... #include<iostream> #inclu ...

  2. AtCoder Beginner Contest 077

    A - Rotation Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement You are g ...

  3. AtCoder Beginner Contest 077 D Small Multiple(最短路)

    水过前三道题之后,一直在写这个题,做不对.总有那么几组数据过不去... 看了看题解是最短路,这思路感觉很神奇.看了下唯一做出来这题的那人的代码,是搜索做的. 标程: 对每个数字x,向x+1建一条花费为 ...

  4. AtCoder Beginner Contest 188 D - Snuke Prime (思维,差分)

    题意:你需要订阅一些服务,每个服务每天需要花费\(c_i\),要从第\(a_i\)用到第\(b_i\)天,你可以购买会员,会员每天需要花费\(C\),但是这天的服务不用再另花钱了,问你订阅这些服务的最 ...

  5. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  6. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  7. AtCoder Beginner Contest 068 ABCD题

    A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...

  8. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  9. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

随机推荐

  1. linux系统级别的计划任务及其扩展anacrontab

    这个是系统设置好了,清理系统垃圾或者是自动执行某些脚本的系统任务,一般我们做了解就行了,不要更改配置文件是/etc/conrtab SHELL:就是运行计划任务的解释器,默认是bash PATH:执行 ...

  2. linux引导和登录/注销配置文件

    引导和登录/注销 /etc/issue & /etc/issue.net 这些文件由 mingetty(和类似的程序)读取,用来向从终端(issue)或通过 telnet 会话(issue.n ...

  3. UvaLive1347

    Programming contests became so popular in the year 2397 that the governor of New Earck — the largest ...

  4. Javascript-随滚轮匀速滑动的浮动广告窗动画

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  5. Liferay 7.1发布啦

    下载地址: https://cdn.lfrs.sl/releases.liferay.com/portal/7.1.0-m1/liferay-ce-portal-tomcat-7.1-m1-20180 ...

  6. Mysql的CMD操作

    一.MySQL登录和退出——在CMD模式操作 l  语法格式:mysql.exe –h主机名 –u用户名 –p密码 l  参数说明:   mysql.exe是mysql服务器的主应用程序.   -h代 ...

  7. selenium 常见问题之 nknown error: call function result missing ‘value’

    运行时候出现错误提示如下: 出现该问题原因:chrome浏览器自动升级.导致和chromedriver支持的版本不匹配. 解决方案有两种(本人采用的是第一种方式解决办法.): 1.下载和当前使用的ch ...

  8. php require_once的使用方法

    学习笔记 require_once 语句和 require 语句完全相同,唯一区别是 PHP 会检查该文件是否已经被包含过,如果是则不会再次包含. equire_once() 为了避免重复加载文件. ...

  9. js 常用事件总结

    无论web端还是手机端,用户的交互总伴随着事件监听 下面是我总结的一些常用到的事件 1.监听标签内容变化 非input元素 $(dom).bind('DOMNodeInserted',function ...

  10. 关于Python缩进,我们该了解哪些?

    Python是一门独特的语言,它的代码块是通过缩进(Indentation)来标记的(大部分语言都是使用花括号作为代码块的标记),具有相同缩进的多行代码属于同一个代码块.如果代码莫名其妙的乱缩进,Py ...