博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AtCoder Beginner Contest 077 C - Snuke Festival
阅读量:6311 次
发布时间:2019-06-22

本文共 2313 字,大约阅读时间需要 7 分钟。

题目描述

Problem Statement

The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.

He has N parts for each of the three categories. The size of the i-th upper part is Ai, the size of the i-th middle part is Bi, and the size of the i-th lower part is Ci.

To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.

How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Constraints

  • 1≤N≤10^5
  • 1≤Ai≤10^9(1≤iN)
  • 1≤Bi≤10^9(1≤iN)
  • 1≤Ci≤10^9(1≤iN)
  • All input values are integers.

这道题我当时比赛的时候,因为前两题都很水,但这道题画风明显和前两题不是一个档次,大概起码是提高了一个档次以上,(但大概在大佬眼里还是道水题吧)。

这道题n^3的做法应该是比较简单的,然后我就想了想,搞了个O(nlogn)的方法。

需要详细题解的在下面发评论我再发,先放一下我的代码。

 

#include
#include
#include
using namespace std;long long n,f[100001][5],l=0,r,mid,a[1000001],b[100001],c[100001];int main(){ scanf("%lld",&n); for(int j=1;j<=n;++j) scanf("%lld",&a[j]); for(int j=1;j<=n;++j) scanf("%lld",&b[j]); for(int j=1;j<=n;++j) scanf("%lld",&c[j]); sort(a+1,a+1+n);sort(b+1,b+1+n);sort(c+1,c+1+n); for(int i=1;i<=n;++i) { f[i][1]=i; } for(int j=1;j<=n;++j) { l=1,r=n; while(l<=r) { mid=(l+r)/2; if(b[j]<=a[mid]) { r=mid-1; } else l=mid+1; } f[j][2]=f[j-1][2]+f[r][1]; } for(int j=1;j<=n;++j) { l=1,r=n; while(l<=r) { mid=(l+r)/2; if(c[j]<=b[mid]) { r=mid-1; } else l=mid+1; } f[j][3]=f[j-1][3]+f[r][2]; } printf("%lld",f[n][3]); return 0;}

转载于:https://www.cnblogs.com/slts/p/7787872.html

你可能感兴趣的文章
我的友情链接
查看>>
Nginx+mysql+php-fpm负载均衡配置实例
查看>>
shell脚本操作mysql数据库 (部份参考)
查看>>
MySql之基于ssl安全连接的主从复制
查看>>
informix的逻辑日志和物理日志分析
查看>>
VMware.Workstation Linux与windows实现文件夹共享
查看>>
ARM inlinehook小结
查看>>
wordpress admin https + nginx反向代理配置
查看>>
管理/var/spool/clientmqueue/下的大文件
查看>>
HTML学习笔记1—HTML基础
查看>>
mysql dba系统学习(20)mysql存储引擎MyISAM
查看>>
centos 5.5 64 php imagick 模块错误处理记录
查看>>
apache中文url日志分析--php十六进制字符串转换
查看>>
Ansible--playbook介绍
查看>>
浅谈代理
查看>>
php创建桌面快捷方式实现方法
查看>>
基于jquery实现的超酷动画源码
查看>>
fl包下的TransitionManager的使用
查看>>
Factorialize a Number
查看>>
[USB-Blaster] Error (209040): Can't access JTAG chain
查看>>